ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
PB_CInOutV.c
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------
2 *
3 * -- PBLAS auxiliary 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 PB_CInOutV( PBTYP_T * TYPE, char * ROWCOL, int M, int N, int * DESCA,
21  int K, char * BETA,
22  char * Y, int IY, int JY, int * DESCY, char * YROC,
23  char * * TBETA, char * * YAPTR, int * DYA,
24  int * YAFREE, int * YASUM, int * YAPBY )
25 #else
26 void PB_CInOutV( TYPE, ROWCOL, M, N, DESCA, K,
27  BETA, Y, IY, JY, DESCY, YROC,
28  TBETA, YAPTR, DYA, YAFREE, YASUM, YAPBY )
29 /*
30 * .. Scalar Arguments ..
31 */
32  char * BETA, * ROWCOL, * * TBETA, * YROC;
33  int * YAPBY, * YAFREE, IY, JY, K, M, N, * YASUM;
34  PBTYP_T * TYPE;
35 /*
36 * .. Array Arguments ..
37 */
38  int * DESCA, * DESCY, * DYA;
39  char * Y, * * YAPTR;
40 #endif
41 {
42 /*
43 * Purpose
44 * =======
45 *
46 * PB_CInOutV returns a pointer to an array that contains a one-dimen-
47 * sional input/output subvector which is replicated over the rows or
48 * columns of a submatrix described by DESCA. A subvector is specified
49 * on input to this routine that is reused whenever possible. On return,
50 * the subvector is specified by a pointer to some data, a descriptor
51 * array describing its layout, a logical value indicating if this local
52 * piece of data has been dynamically allocated by this function, a lo-
53 * gical value specifying if sum reduction should occur, and finally a
54 * logical value specifying if it is necessary to copy back the alloca-
55 * ted data to the original data. This routine is specifically designed
56 * for traditional Level 2 like PBLAS operations using an input/output
57 * vector such as PxGEMV, PxSYMV ...
58 *
59 * Notes
60 * =====
61 *
62 * A description vector is associated with each 2D block-cyclicly dis-
63 * tributed matrix. This vector stores the information required to
64 * establish the mapping between a matrix entry and its corresponding
65 * process and memory location.
66 *
67 * In the following comments, the character _ should be read as
68 * "of the distributed matrix". Let A be a generic term for any 2D
69 * block cyclicly distributed matrix. Its description vector is DESC_A:
70 *
71 * NOTATION STORED IN EXPLANATION
72 * ---------------- --------------- ------------------------------------
73 * DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
74 * CTXT_A (global) DESCA[ CTXT_ ] The BLACS context handle, indicating
75 * the NPROW x NPCOL BLACS process grid
76 * A is distributed over. The context
77 * itself is global, but the handle
78 * (the integer value) may vary.
79 * M_A (global) DESCA[ M_ ] The number of rows in the distribu-
80 * ted matrix A, M_A >= 0.
81 * N_A (global) DESCA[ N_ ] The number of columns in the distri-
82 * buted matrix A, N_A >= 0.
83 * IMB_A (global) DESCA[ IMB_ ] The number of rows of the upper left
84 * block of the matrix A, IMB_A > 0.
85 * INB_A (global) DESCA[ INB_ ] The number of columns of the upper
86 * left block of the matrix A,
87 * INB_A > 0.
88 * MB_A (global) DESCA[ MB_ ] The blocking factor used to distri-
89 * bute the last M_A-IMB_A rows of A,
90 * MB_A > 0.
91 * NB_A (global) DESCA[ NB_ ] The blocking factor used to distri-
92 * bute the last N_A-INB_A columns of
93 * A, NB_A > 0.
94 * RSRC_A (global) DESCA[ RSRC_ ] The process row over which the first
95 * row of the matrix A is distributed,
96 * NPROW > RSRC_A >= 0.
97 * CSRC_A (global) DESCA[ CSRC_ ] The process column over which the
98 * first column of A is distributed.
99 * NPCOL > CSRC_A >= 0.
100 * LLD_A (local) DESCA[ LLD_ ] The leading dimension of the local
101 * array storing the local blocks of
102 * the distributed matrix A,
103 * IF( Lc( 1, N_A ) > 0 )
104 * LLD_A >= MAX( 1, Lr( 1, M_A ) )
105 * ELSE
106 * LLD_A >= 1.
107 *
108 * Let K be the number of rows of a matrix A starting at the global in-
109 * dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
110 * that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
111 * receive if these K rows were distributed over NPROW processes. If K
112 * is the number of columns of a matrix A starting at the global index
113 * JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number of co-
114 * lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would receive if
115 * these K columns were distributed over NPCOL processes.
116 *
117 * The values of Lr() and Lc() may be determined via a call to the func-
118 * tion PB_Cnumroc:
119 * Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
120 * Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
121 *
122 * Arguments
123 * =========
124 *
125 * TYPE (local input) pointer to a PBTYP_T structure
126 * On entry, TYPE is a pointer to a structure of type PBTYP_T,
127 * that contains type information (See pblas.h).
128 *
129 * ROWCOL (global input) pointer to CHAR
130 * On entry, ROWCOL specifies if this routine should return a
131 * row or column subvector replicated over the underlying subma-
132 * trix as follows:
133 * = 'R' or 'r': A row subvector is returned,
134 * = 'C' or 'c': A column subvector is returned.
135 *
136 * M (global input) INTEGER
137 * On entry, M specifies the number of rows of the underlying
138 * submatrix described by DESCA. M must be at least zero.
139 *
140 * N (global input) INTEGER
141 * On entry, N specifies the number of columns of the underlying
142 * submatrix described by DESCA. N must be at least zero.
143 *
144 * DESCA (global and local input/output) INTEGER array
145 * On entry, DESCA is an integer array of dimension DLEN_. This
146 * is the array descriptor for the matrix A. EXCEPTIONALLY, THIS
147 * INTERNAL ROUTINE MAY MODIFY DESCA IN ORDER TO MINIMIZE THE
148 * AMOUNT OF DATA TO BE MOVED FOR THE VECTOR Y. SEE PxGEMV FOR
149 * AN EXAMPLE.
150 *
151 * K (global input) INTEGER
152 * On entry, K specifies the length of the non-distributed di-
153 * mension of the subvector sub( Y ). K must be at least zero.
154 *
155 * BETA (global input) pointer to CHAR
156 * On entry, BETA is a scalar the input subvector sub( Y ) must
157 * be scaled by.
158 *
159 * Y (local input) pointer to CHAR
160 * On entry, Y is an array of dimension (LLD_Y, Ky), where LLD_Y
161 * is at least MAX( 1, Lr( K, IY ) ) when YROC is 'R' or 'r'
162 * and MAX( 1, Lr( 1, IY+Ly-1 ) ) otherwise, and, Ky is at
163 * least Lc( 1, JY+Ly-1 ) when YROC is 'R' or 'r' and
164 * Lc( K, JY ) otherwise. Ly is N when ROWCOL is 'R' or 'r' and
165 * M otherwise. Before entry, this array contains the local
166 * entries of the matrix Y.
167 *
168 * IY (global input) INTEGER
169 * On entry, IY specifies Y's global row index, which points to
170 * the beginning of the submatrix sub( Y ).
171 *
172 * JY (global input) INTEGER
173 * On entry, JY specifies Y's global column index, which points
174 * to the beginning of the submatrix sub( Y ).
175 *
176 * DESCY (global and local input) INTEGER array
177 * On entry, DESCY is an integer array of dimension DLEN_. This
178 * is the array descriptor for the matrix Y.
179 *
180 * YROC (global input) pointer to CHAR
181 * On entry, YROC specifies the orientation of the subvector
182 * sub( Y ). When YROC is 'R' or 'r', sub( Y ) is a row vector,
183 * and a column vector otherwise.
184 *
185 * TBETA (local output) pointer to pointer to CHAR
186 * On exit, * TBETA is a scalar to be used locally to scale the
187 * data pointed to by * YAPTR, in order to obtain the correct
188 * result in the original data sub( Y ).
189 *
190 * YAPTR (local output) pointer to pointer to CHAR
191 * On exit, * YAPTR is an array containing the same data as the
192 * subvector sub( Y ) which is replicated over the rows or co-
193 * lumns of the underlying matrix as specified by ROWCOL and
194 * DESCA.
195 *
196 * DYA (global and local output) INTEGER array
197 * On exit, DYA is a descriptor array of dimension DLEN_ descri-
198 * bing the data layout of the data pointed to by * YAPTR.
199 *
200 * YAFREE (local output) INTEGER
201 * On exit, YAFREE specifies if it was possible to reuse the
202 * subvector sub( Y ), i.e., if some dynamic memory was alloca-
203 * ted for the data pointed to by * YAPTR or not. When YAFREE is
204 * zero, no dynamic memory was allocated. Otherwise, some dyna-
205 * mic memory was allocated by this function that one MUST re-
206 * lease as soon as possible.
207 *
208 * YASUM (global output) INTEGER
209 * On exit, YASUM specifies if a global sum reduction should be
210 * performed to obtain the correct sub( Y ). When YASUM is zero,
211 * no reduction is to be performed, otherwise reduction should
212 * occur.
213 *
214 * YAPBY (global output) INTEGER
215 * On exit, YAPBY specifies if the data pointed to by * YAPTR
216 * must be move back onto sub( Y ) to obtain the correct result.
217 * When YAPBY is zero, no supplementary data movement is neces-
218 * sary, otherwise a data redistribution should occur.
219 *
220 * -- Written on April 1, 1998 by
221 * Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
222 *
223 * ---------------------------------------------------------------------
224 */
225 /*
226 * .. Local Scalars ..
227 */
228  int Acol, Aimb, Ainb, AisD, AisR, Amb, Amp, Anb, Anq, Arow, Ycol,
229  Yii, Yimb, Yimb1, Yinb, Yinb1, YisD, YisR, YisRow, Yjj, Yld,
230  Ymb, Ymp, Ynb, Ynq, Yrow, ctxt, izero=0, nprow, myrow, npcol,
231  mycol;
232 /* ..
233 * .. Executable Statements ..
234 *
235 */
236 /*
237 * Initialize the output parameters to a default value
238 */
239  *YAFREE = 0;
240  *YASUM = 0;
241  *YAPBY = 0;
242  *YAPTR = NULL;
243  *TBETA = BETA;
244 /*
245 * Quick return if possible
246 */
247  if( ( M <= 0 ) || ( N <= 0 ) || ( K <= 0 ) )
248  {
249  if( Mupcase( ROWCOL[0] ) == CROW )
250  {
251  PB_Cdescset( DYA, K, N, 1, DESCA[INB_], 1, DESCA[NB_], DESCA[RSRC_],
252  DESCA[CSRC_], DESCA[CTXT_], 1 );
253  }
254  else
255  {
256  PB_Cdescset( DYA, M, K, DESCA[IMB_], 1, DESCA[MB_], 1, DESCA[RSRC_],
257  DESCA[CSRC_], DESCA[CTXT_], DESCA[LLD_] );
258  }
259  return;
260  }
261 /*
262 * Retrieve process grid information
263 */
264  Cblacs_gridinfo( ( ctxt = DESCY[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
265 /*
266 * Retrieve sub( Y )'s local information: Yii, Yjj, Yrow, Ycol
267 */
268  Minfog2l( IY, JY, DESCY, nprow, npcol, myrow, mycol, Yii, Yjj, Yrow, Ycol );
269 /*
270 * Is sub( Y ) distributed or not, replicated or not ?
271 */
272  if( ( YisRow = ( Mupcase( YROC[0] ) == CROW ) ) != 0 )
273  {
274  YisD = ( ( Ycol >= 0 ) && ( npcol > 1 ) );
275  YisR = ( ( Yrow == -1 ) || ( nprow == 1 ) );
276  }
277  else
278  {
279  YisD = ( ( Yrow >= 0 ) && ( nprow > 1 ) );
280  YisR = ( ( Ycol == -1 ) || ( npcol == 1 ) );
281  }
282 
283  Aimb = DESCA[IMB_ ]; Ainb = DESCA[INB_ ];
284  Amb = DESCA[MB_ ]; Anb = DESCA[NB_ ];
285  Arow = DESCA[RSRC_]; Acol = DESCA[CSRC_];
286 
287  if( Mupcase( ROWCOL[0] ) == CROW )
288  {
289 /*
290 * Want a row vector
291 */
292  AisR = ( ( Arow < 0 ) || ( nprow == 1 ) );
293 
294  if( YisRow )
295  {
296 /*
297 * It is possible to reuse sub( Y ) iff sub( Y ) is already a row vector.
298 */
299  AisD = ( ( Acol >= 0 ) && ( npcol > 1 ) );
300 
301  Yinb = DESCY[INB_]; Ynb = DESCY[NB_];
302  Mfirstnb( Yinb1, N, JY, Yinb, Ynb );
303 /*
304 * sub( Y ) is aligned with A (reuse condition) iff both operands are not
305 * distributed, or both of them are distributed and start in the same process
306 * column and either N is smaller than the first blocksize of sub( Y ) and A,
307 * or their column blocking factors match.
308 */
309  if( ( !AisD && !YisD ) ||
310  ( ( AisD && YisD ) &&
311  ( ( Acol == Ycol ) &&
312  ( ( ( Ainb >= N ) && ( Yinb1 >= N ) ) ||
313  ( ( Ainb == Yinb1 ) && ( Anb == Ynb ) ) ) ) ) )
314  {
315  Mnumroc( Ynq, N, 0, Yinb1, Ynb, mycol, Ycol, npcol );
316  Ymp = ( YisR ? K : ( ( myrow == Yrow ) ? K : 0 ) );
317 
318  if( YisR )
319  {
320 /*
321 * If sub( Y ) is replicated, there is no need to move sub( Y ) after the
322 * operation (*YAPBY = 0), and it can be reused.
323 */
324  *YAPBY = 0;
325  Yld = DESCY[ LLD_ ];
326  if( Ynq > 0 )
327  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
328 
329  if( AisR )
330  {
331 /*
332 * If A is replicated as well, use BETA in every process row, and do not combine
333 * the local results.
334 */
335  *TBETA = BETA;
336  *YASUM = 0;
337  }
338  else
339  {
340 /*
341 * Otherwise, use BETA in process row Arow and zero elsewhere. Reduce the local
342 * result if there is more than one row in the process grid.
343 */
344  *TBETA = ( ( myrow == Arow ) ? BETA : TYPE->zero );
345  *YASUM = ( nprow > 1 );
346 /*
347 * If some process rows do not own any entries of A, better set sub( Y ) to zero
348 * in those processes.
349 */
350  Mnumroc( Amp, M, 0, Aimb, Amb, myrow, Arow, nprow );
351  if( Amp <= 0 )
352  TYPE->Ftzscal( C2F_CHAR( ALL ), &K, &Ynq, &izero, *TBETA,
353  *YAPTR, &Yld );
354  }
355  }
356  else
357  {
358 /*
359 * sub( Y ) is not replicated, the descriptor of A may need to be modified ...
360 */
361  if( AisR )
362  {
363 /*
364 * If A is replicated, use only the copy in the process row where sub( Y )
365 * resides -> modify DESCA !!!
366 */
367  *TBETA = BETA;
368  *YASUM = 0;
369  *YAPBY = 0;
370  Yld = DESCY[ LLD_ ];
371  DESCA[ IMB_ ] = M;
372  DESCA[ RSRC_ ] = Yrow;
373  if( ( Ynq > 0 ) && ( Ymp > 0 ) )
374  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
375  }
376  else
377  {
378  if( Mspan( M, 0, Aimb, Amb, Arow, nprow ) )
379  {
380 /*
381 * Otherwise, A is not replicated, let assume in addition that it spans more
382 * than one process row
383 */
384  *YASUM = ( nprow > 1 );
385  *YAPBY = 0;
386 
387  if( myrow == Yrow )
388  {
389 /*
390 * Reuse sub( Y ). If there is no entries of A in the process row where sub( Y )
391 * resides, better scale it by BETA immediately.
392 */
393  *TBETA = BETA;
394  Yld = DESCY[ LLD_ ];
395  if( Ynq > 0 )
396  {
397  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
398  Mnumroc( Amp, M, 0, Aimb, Amb, myrow, Arow, nprow );
399  if( Amp <= 0 )
400  TYPE->Ftzscal( C2F_CHAR( ALL ), &K, &Ynq, &izero,
401  *TBETA, *YAPTR, &Yld );
402  }
403  }
404  else
405  {
406 /*
407 * Allocate space in the other process rows and initialize to zero.
408 */
409  *TBETA = TYPE->zero;
410  Yld = MAX( 1, K );
411  if( Ynq > 0 )
412  {
413  *YAPTR = PB_Cmalloc( K * Ynq * TYPE->size );
414  *YAFREE = 1;
415  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ),
416  &K, &Ynq, &izero, *TBETA, *TBETA,
417  *YAPTR, &Yld );
418  }
419  }
420  }
421  else
422  {
423 /*
424 * A spans only one process row
425 */
426  if( Yrow == Arow )
427  {
428 /*
429 * A and sub( Y ) resides in the same process row
430 */
431  *TBETA = BETA;
432  *YASUM = 0;
433  *YAPBY = 0;
434  Yld = DESCY[ LLD_ ];
435  if( ( myrow == Yrow ) && ( Ynq > 0 ) )
436  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
437  }
438  else
439  {
440 /*
441 * If sub( Y ) resides in another process row, then allocate zero-data in
442 * process row where A resides, and set *YAPBY to 1, so that this data will be
443 * added (moved) after the local operation has been performed.
444 */
445  *TBETA = TYPE->zero;
446  *YASUM = 0;
447  *YAPBY = 1;
448  Yrow = Arow;
449  Yld = MAX( 1, K );
450  if( myrow == Arow )
451  {
452  if( Ynq > 0 )
453  {
454  *YAPTR = PB_Cmalloc( K * Ynq * TYPE->size );
455  *YAFREE = 1;
456  TYPE->Ftzpad( C2F_CHAR( ALL ),
457  C2F_CHAR( NOCONJG ), &K, &Ynq,
458  &izero, *TBETA, *TBETA, *YAPTR,
459  &Yld );
460  }
461  }
462  }
463  }
464  }
465  }
466 /*
467 * Describe the resulting operand. Note that when reduction should occur, Yrow
468 * contains the destination row. Assuming every process row needs the result,
469 * Yrow is then -1.
470 */
471  MDescSet( DYA, K, N, K, Yinb1, 1, Ynb, Yrow, Ycol, ctxt, Yld );
472  return;
473  }
474  }
475 /*
476 * sub( Y ) cannot be reused, set TBETA to zero for the local operation, and
477 * force YAPBY to 1 for the later update of sub( Y ).
478 */
479  *TBETA = TYPE->zero;
480  *YAPBY = 1;
481  Mnumroc( Anq, N, 0, Ainb, Anb, mycol, Acol, npcol );
482  Yld = MAX( 1, K );
483 
484  if( YisR )
485  {
486 /*
487 * If sub( Y ) is replicated, allocate space in every process row owning some
488 * columns of A and initialize it to zero. There may be some wasted space
489 * (suppose A was residing in just one row), however, it is hoped that moving
490 * back this data to sub( Y ) will then be cheaper ...
491 */
492  *YASUM = ( AisR ? 0 : ( nprow > 1 ) );
493  Arow = -1;
494  if( Anq > 0 )
495  {
496  *YAPTR = PB_Cmalloc( K * Anq * TYPE->size );
497  *YAFREE = 1;
498  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K, &Anq,
499  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
500  }
501  }
502  else
503  {
504 /*
505 * sub( Y ) resides within only one process row
506 */
507  if( AisR )
508  {
509 /*
510 * If A is replicated, then modify sub( A ) so that only one process row will
511 * compute the result before moving it back to sub( Y ).
512 */
513  *YASUM = 0;
514  DESCA[ IMB_ ] = M;
515 
516  if( YisRow )
517  {
518 /*
519 * Choose different process row than Yrow for better performance (more links)
520 * of the later move-back phase.
521 */
522  DESCA[RSRC_] = Arow = MModSub1( Yrow, nprow );
523  }
524  else
525  {
526  DESCA[RSRC_] = Arow = 0;
527  }
528  if( ( myrow == Arow ) && ( Anq > 0 ) )
529  {
530  *YAPTR = PB_Cmalloc( K * Anq * TYPE->size );
531  *YAFREE = 1;
532  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K, &Anq,
533  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
534  }
535  }
536  else
537  {
538  if( Mspan( M, 0, Aimb, Amb, Arow, nprow ) )
539  {
540 /*
541 * If A is not replicated, and spans more than just one process row, then
542 * allocate space in every process row and zero it.
543 */
544  *YASUM = ( nprow > 1 );
545  if( Anq > 0 )
546  {
547  *YAPTR = PB_Cmalloc( K * Anq * TYPE->size );
548  *YAFREE = 1;
549  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K, &Anq,
550  &izero, *TBETA, *TBETA, *YAPTR, &K );
551  }
552  }
553  else
554  {
555 /*
556 * If A is not replicated, and spans only one process row, then allocate space
557 * within that process row and zero it.
558 */
559  *YASUM = 0;
560  if( ( myrow == Arow ) && ( Anq > 0 ) )
561  {
562  *YAPTR = PB_Cmalloc( K * Anq * TYPE->size );
563  *YAFREE = 1;
564  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K, &Anq,
565  &izero, *TBETA, *TBETA, *YAPTR, &K );
566  }
567  }
568  }
569  }
570 /*
571 * Describe the resulting operand. Note that when reduction should occur, Arow
572 * contains the destination row. Assuming every process row needs the result,
573 * Arow is then -1.
574 */
575  MDescSet( DYA, K, N, K, Ainb, 1, Anb, Arow, Acol, ctxt, Yld );
576  }
577  else
578  {
579 /*
580 * Want a column vector
581 */
582  AisR = ( ( Acol < 0 ) || ( npcol == 1 ) );
583 
584  if( !YisRow )
585  {
586 /*
587 * It is possible to reuse sub( Y ) iff sub( Y ) is already a column vector.
588 */
589  AisD = ( ( Arow >= 0 ) && ( nprow > 1 ) );
590 
591  Yimb = DESCY[IMB_]; Ymb = DESCY[MB_];
592  Mfirstnb( Yimb1, M, IY, Yimb, Ymb );
593 /*
594 * sub( Y ) is aligned with A (reuse condition) iff both operands are not
595 * distributed, or both of them are distributed and start in the same process
596 * row and either M is smaller than the first blocksize of sub( Y ) and A, or
597 * their row blocking factors match.
598 */
599  if( ( !AisD && !YisD ) ||
600  ( ( AisD && YisD ) &&
601  ( ( Arow == Yrow ) &&
602  ( ( ( Aimb >= M ) && ( Yimb1 >= M ) ) ||
603  ( ( Aimb == Yimb1 ) && ( Amb == Ymb ) ) ) ) ) )
604  {
605  Mnumroc( Ymp, M, 0, Yimb1, Ymb, myrow, Yrow, nprow );
606  Ynq = ( YisR ? K : ( ( mycol == Ycol ) ? K : 0 ) );
607 
608  if( YisR )
609  {
610 /*
611 * If sub( Y ) is replicated, there is no need to move sub( Y ) after the
612 * operation (*YAPBY = 0), and it can be reused.
613 */
614  *YAPBY = 0;
615  Yld = DESCY[ LLD_ ];
616  if( Ymp > 0 )
617  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
618 
619  if( AisR )
620  {
621 /*
622 * If A is replicated as well, use BETA in every process column, and do not
623 * combine the local results.
624 */
625  *TBETA = BETA;
626  *YASUM = 0;
627  }
628  else
629  {
630 /*
631 * Otherwise, use BETA in process column Acol and zero elsewhere. Reduce the
632 * local result if there is more than one column in the process grid.
633 */
634  *TBETA = ( ( mycol == Acol ) ? BETA : TYPE->zero );
635  *YASUM = ( npcol > 1 );
636 /*
637 * If some process columns do not own any entries of A, better set sub( Y ) to
638 * zero in those processes.
639 */
640  Mnumroc( Anq, N, 0, Ainb, Anb, mycol, Acol, npcol );
641  if( Anq <= 0 )
642  TYPE->Ftzscal( C2F_CHAR( ALL ), &Ymp, &K, &izero, *TBETA,
643  *YAPTR, &Yld );
644  }
645  }
646  else
647  {
648 /*
649 * sub( Y ) is not replicated, the descriptor of A may need to be modified ...
650 */
651  if( AisR )
652  {
653 /*
654 * If A is replicated, use only the copy in the process column where sub( Y )
655 * resides -> modify DESCA !!!
656 */
657  *TBETA = BETA;
658  *YASUM = 0;
659  *YAPBY = 0;
660  Yld = DESCY[ LLD_ ];
661  DESCA[ INB_ ] = N;
662  DESCA[ CSRC_ ] = Ycol;
663  if( ( Ymp > 0 ) && ( Ynq > 0 ) )
664  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
665  }
666  else
667  {
668  if( Mspan( N, 0, Ainb, Anb, Acol, npcol ) )
669  {
670 /*
671 * Otherwise, A is not replicated, let assume in addition that it spans more
672 * than one process column
673 */
674  *YASUM = ( npcol > 1 );
675  *YAPBY = 0;
676 
677  if( mycol == Ycol )
678  {
679 /*
680 * Reuse sub( Y ). If there is no entries of A in the process column where
681 * sub( Y ) resides, better scale it by BETA immediately.
682 */
683  *TBETA = BETA;
684  Yld = DESCY[ LLD_ ];
685  if( Ymp > 0 )
686  {
687  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
688  Mnumroc( Anq, N, 0, Ainb, Anb, mycol, Acol, npcol );
689  if( Anq <= 0 )
690  TYPE->Ftzscal( C2F_CHAR( ALL ), &Ymp, &K, &izero,
691  *TBETA, *YAPTR, &Yld );
692  }
693  }
694  else
695  {
696 /*
697 * Allocate space in the other process columns and initialize to zero.
698 */
699  *TBETA = TYPE->zero;
700  Yld = MAX( 1, Ymp );
701  if( Ymp > 0 )
702  {
703  *YAPTR = PB_Cmalloc( Ymp * K * TYPE->size );
704  *YAFREE = 1;
705  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ),
706  &Ymp, &K, &izero, *TBETA, *TBETA,
707  *YAPTR, &Yld );
708  }
709  }
710  }
711  else
712  {
713 /*
714 * A spans only one process column
715 */
716  if( Ycol == Acol )
717  {
718 /*
719 * A and sub( Y ) resides in the same process column
720 */
721  *TBETA = BETA;
722  *YASUM = 0;
723  *YAPBY = 0;
724  Yld = DESCY[ LLD_ ];
725  if( ( mycol == Ycol ) && ( Ymp > 0 ) )
726  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
727  }
728  else
729  {
730 /*
731 * If sub( Y ) resides in another process column, then allocate zero-data in
732 * process column where A resides, and set *YAPBY to 1, so that this data will
733 * be added (moved) after the local operation has been performed.
734 */
735  *TBETA = TYPE->zero;
736  *YASUM = 0;
737  *YAPBY = 1;
738  Ycol = Acol;
739  Yld = MAX( 1, Ymp ) ;
740  if( mycol == Acol )
741  {
742  if( Ymp > 0 )
743  {
744  *YAPTR = PB_Cmalloc( Ymp * K * TYPE->size );
745  *YAFREE = 1;
746  TYPE->Ftzpad( C2F_CHAR( ALL ),
747  C2F_CHAR( NOCONJG ), &Ymp, &K,
748  &izero, *TBETA, *TBETA, *YAPTR,
749  &Yld );
750  }
751  }
752  }
753  }
754  }
755  }
756 /*
757 * Describe the resulting operand. Note that when reduction should occur, Ycol
758 * contains the destination column. Assuming every process column needs the
759 * result, Ycol is then -1.
760 */
761  MDescSet( DYA, M, K, Yimb1, K, Ymb, 1, Yrow, Ycol, ctxt, Yld );
762  return;
763  }
764  }
765 /*
766 * sub( Y ) cannot be reused, set TBETA to zero for the local operation, and
767 * force YAPBY to 1 for the later update of sub( Y ).
768 */
769  *TBETA = TYPE->zero;
770  *YAPBY = 1;
771  Mnumroc( Amp, M, 0, Aimb, Amb, myrow, Arow, nprow );
772  Yld = MAX( 1, Amp );
773 
774  if( YisR )
775  {
776 /*
777 * If sub( Y ) is replicated, allocate space in every process column owning some
778 * rows of A and initialize it to zero. There may be some wasted space (suppose
779 * A was residing in just one column), however, it is hoped that moving back
780 * this data to sub( Y ) will then be cheaper ...
781 */
782  *YASUM = ( AisR ? 0 : ( npcol > 1 ) );
783  Acol = -1;
784  if( Amp > 0 )
785  {
786  *YAPTR = PB_Cmalloc( Amp * K * TYPE->size );
787  *YAFREE = 1;
788  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp, &K,
789  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
790  }
791  }
792  else
793  {
794 /*
795 * sub( Y ) resides within only one process column
796 */
797  if( AisR )
798  {
799 /*
800 * If A is replicated, then modify sub( A ) so that only one process column will
801 * compute the result before moving it back to sub( Y ).
802 */
803  *YASUM = 0;
804  DESCA[ INB_ ] = N;
805 
806  if( YisRow )
807  {
808  DESCA[ CSRC_ ] = Acol = 0;
809  }
810  else
811  {
812 /*
813 * Choose different process column than Ycol for better performance (more links)
814 * of the later move-back phase.
815 */
816  DESCA[ CSRC_ ] = Acol = MModSub1( Ycol, npcol );
817  }
818  if( ( mycol == Acol ) && ( Amp > 0 ) )
819  {
820  *YAPTR = PB_Cmalloc( Amp * K * TYPE->size );
821  *YAFREE = 1;
822  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp, &K,
823  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
824  }
825  }
826  else
827  {
828  if( Mspan( N, 0, Ainb, Anb, Acol, npcol ) )
829  {
830 /*
831 * If A is not replicated, and spans more than just one process column, then
832 * allocate space in every process column and zero it.
833 */
834  *YASUM = ( npcol > 1 );
835  if( Amp > 0 )
836  {
837  *YAPTR = PB_Cmalloc( Amp * K * TYPE->size );
838  *YAFREE = 1;
839  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp, &K,
840  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
841  }
842  }
843  else
844  {
845 /*
846 * If A is not replicated, and spans only one process column, then allocate
847 * space within that process column and zero it.
848 */
849  *YASUM = 0;
850  if( ( mycol == Acol ) && ( Amp > 0 ) )
851  {
852  *YAPTR = PB_Cmalloc( Amp * K * TYPE->size );
853  *YAFREE = 1;
854  TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp, &K,
855  &izero, *TBETA, *TBETA, *YAPTR, &Yld );
856  }
857  }
858  }
859  }
860 /*
861 * Describe the resulting operand. Note that when reduction should occur, Acol
862 * contains the destination column. Assuming every process column needs the
863 * result, Acol is then -1.
864 */
865  MDescSet( DYA, M, K, Aimb, K, Amb, 1, Arow, Acol, ctxt, Yld );
866  }
867 /*
868 * End of PB_CInOutV
869 */
870 }
TYPE
#define TYPE
Definition: clamov.c:7
MB_
#define MB_
Definition: PBtools.h:43
MDescSet
#define MDescSet(desc, m, n, imb, inb, mb, nb, rsrc, csrc, ictxt, lld)
Definition: PBtools.h:499
NB_
#define NB_
Definition: PBtools.h:44
CSRC_
#define CSRC_
Definition: PBtools.h:46
Mspan
#define Mspan(n_, i_, inb_, nb_, srcproc_, nprocs_)
Definition: PBtools.h:160
NOCONJG
#define NOCONJG
Definition: PBblas.h:45
Mnumroc
#define Mnumroc(np_, n_, i_, inb_, nb_, proc_, srcproc_, nprocs_)
Definition: PBtools.h:222
PB_CInOutV
void PB_CInOutV(PBTYP_T *TYPE, char *ROWCOL, int M, int N, int *DESCA, int K, char *BETA, char *Y, int IY, int JY, int *DESCY, char *YROC, char **TBETA, char **YAPTR, int *DYA, int *YAFREE, int *YASUM, int *YAPBY)
Definition: PB_CInOutV.c:26
LLD_
#define LLD_
Definition: PBtools.h:47
CROW
#define CROW
Definition: PBblacs.h:21
IMB_
#define IMB_
Definition: PBtools.h:41
PB_Cdescset
void PB_Cdescset()
Minfog2l
#define Minfog2l(i_, j_, desc_, nr_, nc_, r_, c_, ii_, jj_, pr_, pc_)
Definition: PBtools.h:428
Mfirstnb
#define Mfirstnb(inbt_, n_, i_, inb_, nb_)
Definition: PBtools.h:139
RSRC_
#define RSRC_
Definition: PBtools.h:45
PB_Cmalloc
char * PB_Cmalloc()
ALL
#define ALL
Definition: PBblas.h:50
INB_
#define INB_
Definition: PBtools.h:42
C2F_CHAR
#define C2F_CHAR(a)
Definition: pblas.h:121
MModSub1
#define MModSub1(I, d)
Definition: PBtools.h:105
MAX
#define MAX(a_, b_)
Definition: PBtools.h:77
Cblacs_gridinfo
void Cblacs_gridinfo()
PBTYP_T
Definition: pblas.h:325
Mupcase
#define Mupcase(C)
Definition: PBtools.h:83
Mptr
#define Mptr(a_, i_, j_, lda_, siz_)
Definition: PBtools.h:132
CTXT_
#define CTXT_
Definition: PBtools.h:38