File: PB_CInOutV2.c

package info (click to toggle)
scalapack 1.8.0-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 32,240 kB
  • ctags: 29,143
  • sloc: fortran: 288,069; ansic: 64,035; makefile: 1,911
file content (884 lines) | stat: -rw-r--r-- 33,702 bytes parent folder | download | duplicates (10)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
/* ---------------------------------------------------------------------
*
*  -- PBLAS auxiliary routine (version 2.0) --
*     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
*     and University of California, Berkeley.
*     April 1, 1998
*
*  ---------------------------------------------------------------------
*/
/*
*  Include files
*/
#include "../pblas.h"
#include "../PBpblas.h"
#include "../PBtools.h"
#include "../PBblacs.h"
#include "../PBblas.h"

#ifdef __STDC__
void PB_CInOutV2( PBTYP_T * TYPE, char * CONJUG, char * ROWCOL, int M,
                  int N, int KA, int * DESCA, int K, char * Y, int IY,
                  int JY, int * DESCY, char * YROC, char * * YAPTR,
                  int * DYA, int * YAFREE, int * YASUM, int * YAPBY )
#else
void PB_CInOutV2( TYPE, CONJUG, ROWCOL, M, N, KA, DESCA, K, Y, IY, JY,
                  DESCY, YROC, YAPTR, DYA, YAFREE, YASUM, YAPBY )
/*
*  .. Scalar Arguments ..
*/
   char           * CONJUG, * ROWCOL, * YROC;
   int            * YAPBY, * YAFREE, IY, JY, K, KA, M, N, * YASUM;
   PBTYP_T        * TYPE;
/*
*  .. Array Arguments ..
*/
   int            * DESCA, * DESCY, * DYA;
   char           * Y, * * YAPTR;
#endif
{
/*
*  Purpose
*  =======
*
*  PB_CInOutV2  returns a pointer to an array that contains a one-dimen-
*  sional  input/output subvector  which  is replicated over the rows or
*  columns of a submatrix described by DESCA. A  subvector is  specified
*  on input to this routine that is reused whenever possible. On return,
*  the subvector is specified  by  a  pointer to some data, a descriptor
*  array describing its layout, a logical value indicating if this local
*  piece of data has been dynamically allocated by this function, a  lo-
*  gical  value  specifying if sum reduction should occur, and finally a
*  logical  value specifying if it is necessary to copy back the alloca-
*  ted data to the original data. This routine is specifically  designed
*  for  traditional Level 2 like PBLAS  operations using an input/output
*  vector such as PxTRSV.
*
*  Notes
*  =====
*
*  A description  vector  is associated with each 2D block-cyclicly dis-
*  tributed matrix.  This  vector  stores  the  information  required to
*  establish the  mapping  between a  matrix entry and its corresponding
*  process and memory location.
*
*  In  the  following  comments,   the character _  should  be  read  as
*  "of  the  distributed  matrix".  Let  A  be a generic term for any 2D
*  block cyclicly distributed matrix.  Its description vector is DESC_A:
*
*  NOTATION         STORED IN       EXPLANATION
*  ---------------- --------------- ------------------------------------
*  DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
*  CTXT_A  (global) DESCA[ CTXT_  ] The BLACS context handle, indicating
*                                   the NPROW x NPCOL BLACS process grid
*                                   A  is  distributed over. The context
*                                   itself  is  global,  but  the handle
*                                   (the integer value) may vary.
*  M_A     (global) DESCA[ M_     ] The  number of rows in the distribu-
*                                   ted matrix A, M_A >= 0.
*  N_A     (global) DESCA[ N_     ] The number of columns in the distri-
*                                   buted matrix A, N_A >= 0.
*  IMB_A   (global) DESCA[ IMB_   ] The number of rows of the upper left
*                                   block of the matrix A, IMB_A > 0.
*  INB_A   (global) DESCA[ INB_   ] The  number  of columns of the upper
*                                   left   block   of   the  matrix   A,
*                                   INB_A > 0.
*  MB_A    (global) DESCA[ MB_    ] The blocking factor used to  distri-
*                                   bute the last  M_A-IMB_A  rows of A,
*                                   MB_A > 0.
*  NB_A    (global) DESCA[ NB_    ] The blocking factor used to  distri-
*                                   bute the last  N_A-INB_A  columns of
*                                   A, NB_A > 0.
*  RSRC_A  (global) DESCA[ RSRC_  ] The process row over which the first
*                                   row of the matrix  A is distributed,
*                                   NPROW > RSRC_A >= 0.
*  CSRC_A  (global) DESCA[ CSRC_  ] The  process column  over  which the
*                                   first column of  A  is  distributed.
*                                   NPCOL > CSRC_A >= 0.
*  LLD_A   (local)  DESCA[ LLD_   ] The  leading dimension  of the local
*                                   array  storing  the  local blocks of
*                                   the distributed matrix A,
*                                   IF( Lc( 1, N_A ) > 0 )
*                                      LLD_A >= MAX( 1, Lr( 1, M_A ) )
*                                   ELSE
*                                      LLD_A >= 1.
*
*  Let K be the number of  rows of a matrix A starting at the global in-
*  dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
*  that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
*  receive if these K rows were distributed over NPROW processes.  If  K
*  is the number of columns of a matrix  A  starting at the global index
*  JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number  of co-
*  lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would  receive if
*  these K columns were distributed over NPCOL processes.
*
*  The values of Lr() and Lc() may be determined via a call to the func-
*  tion PB_Cnumroc:
*  Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
*  Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
*
*  Arguments
*  =========
*
*  TYPE    (local input) pointer to a PBTYP_T structure
*          On entry,  TYPE  is a pointer to a structure of type PBTYP_T,
*          that contains type information (See pblas.h).
*
*  CONJUG  (global input) pointer to CHAR
*          On  entry,  CONJUG  specifies  if  this routine should return
*          the conjugate subvector as follows:
*             = 'N' or 'n':           The initial subvector is returned,
*             = 'Z' or 'z':         The conjugate subvector is returned.
*
*  ROWCOL  (global input) pointer to CHAR
*          On entry, ROWCOL  specifies  if  this routine should return a
*          row or column subvector replicated over the underlying subma-
*          trix as follows:
*             = 'R' or 'r':                 A row subvector is returned,
*             = 'C' or 'c':              A column subvector is returned.
*
*  M       (global input) INTEGER
*          On entry,  M  specifies the number of rows of  the underlying
*          submatrix described by DESCA. M must be at least zero.
*
*  N       (global input) INTEGER
*          On entry, N specifies the number of columns of the underlying
*          submatrix described by DESCA. N must be at least zero.
*
*  KA      (global input) INTEGER
*          On entry, KA  specifies a global row index when ROWCOL is 'R'
*          or 'r' and a global column index otherwise. This index deter-
*          mines a process row or column in which the  output  subvector
*          contains a copy of the input subvector.
*
*  DESCA   (global and local input/output) INTEGER array
*          On entry, DESCA is an integer array of dimension DLEN_.  This
*          is the array descriptor for the matrix A. EXCEPTIONALLY, THIS
*          INTERNAL  ROUTINE  MAY  MODIFY DESCA IN ORDER TO MINIMIZE THE
*          AMOUNT OF DATA TO BE MOVED FOR THE VECTOR Y. SEE  PxGEMV  FOR
*          AN EXAMPLE.
*
*  K       (global input) INTEGER
*          On entry,  K  specifies the length of the non-distributed di-
*          mension of the subvector sub( Y ). K must be at least zero.
*
*  Y       (local input) pointer to CHAR
*          On entry, Y is an array of dimension (LLD_Y, Ky), where LLD_Y
*          is   at  least  MAX( 1, Lr( K, IY ) ) when YROC is 'R' or 'r'
*          and  MAX( 1, Lr( 1, IY+Ly-1 ) )   otherwise, and,  Ky  is  at
*          least  Lc( 1, JY+Ly-1 )   when   YROC  is  'R'  or  'r'   and
*          Lc( K, JY ) otherwise. Ly is N when  ROWCOL is 'R' or 'r' and
*          M  otherwise.  Before  entry,  this array  contains the local
*          entries of the  matrix Y.
*
*  IY      (global input) INTEGER
*          On entry, IY  specifies Y's global row index, which points to
*          the beginning of the submatrix sub( Y ).
*
*  JY      (global input) INTEGER
*          On entry, JY  specifies Y's global column index, which points
*          to the beginning of the submatrix sub( Y ).
*
*  DESCY   (global and local input) INTEGER array
*          On entry, DESCY  is an integer array of dimension DLEN_. This
*          is the array descriptor for the matrix Y.
*
*  YROC    (global input) pointer to CHAR
*          On entry,  YROC  specifies  the  orientation of the subvector
*          sub( Y ). When YROC is 'R' or 'r',  sub( Y ) is a row vector,
*          and a column vector otherwise.
*
*  YAPTR   (local output) pointer to pointer to CHAR
*          On exit, * YAPTR  is an array containing the same data as the
*          subvector  sub( Y )  which is replicated over the rows or co-
*          lumns of the  underlying  matrix  as  specified by ROWCOL and
*          DESCA.
*
*  DYA     (global and local output) INTEGER array
*          On exit, DYA is a descriptor array of dimension DLEN_ descri-
*          bing the data layout of the data pointed to by * YAPTR.
*
*  YAFREE  (local output) INTEGER
*          On exit, YAFREE  specifies  if  it  was possible to reuse the
*          subvector sub( Y ),  i.e., if some dynamic memory was alloca-
*          ted for the data pointed to by * YAPTR or not. When YAFREE is
*          zero, no  dynamic memory was allocated. Otherwise, some dyna-
*          mic memory  was  allocated by this function that one MUST re-
*          lease as soon as possible.
*
*  YASUM   (global output) INTEGER
*          On exit, YASUM  specifies if a global sum reduction should be
*          performed to obtain the correct sub( Y ). When YASUM is zero,
*          no reduction  is  to be performed, otherwise reduction should
*          occur.
*
*  YAPBY   (global output) INTEGER
*          On exit, YAPBY  specifies  if  the data pointed to by * YAPTR
*          must be move back onto sub( Y ) to obtain the correct result.
*          When YAPBY is zero, no supplementary data movement is  neces-
*          sary, otherwise a data redistribution should occur.
*
*  -- Written on April 1, 1998 by
*     Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
*  ---------------------------------------------------------------------
*/
/*
*  .. Local Scalars ..
*/
   int            Acol, Acoldst, Aimb, Ainb, AisD, AisR, Amb, Amp, Anb, Anq,
                  Arow, Arowdst, Ycol, Yii, Yimb, Yimb1, Yinb, Yinb1, YisD,
                  YisR, YisRow, Yjj, Yld, Ymb, Ymp, Ynb, Ynq, Yrow, ctxt,
                  izero=0, nprow, myrow, npcol, mycol;
/* ..
*  .. Executable Statements ..
*
*/
/*
*  Initialize the output parameters to a default value
*/
   *YAFREE = 0;
   *YASUM  = 0;
   *YAPBY  = 0;
   *YAPTR  = NULL;
/*
*  Quick return if possible
*/
   if( ( M <= 0 ) || ( N <= 0 ) || ( K <= 0 ) )
   {
      if( Mupcase( ROWCOL[0] ) == CROW )
      {
         PB_Cdescset( DYA, K, N, 1, DESCA[INB_], 1, DESCA[NB_], DESCA[RSRC_],
                      DESCA[CSRC_], DESCA[CTXT_], 1 );
      }
      else
      {
         PB_Cdescset( DYA, M, K, DESCA[IMB_], 1, DESCA[MB_], 1, DESCA[RSRC_],
                      DESCA[CSRC_], DESCA[CTXT_], DESCA[LLD_] );
      }
      return;
   }
/*
*  Retrieve process grid information
*/
   Cblacs_gridinfo( ( ctxt = DESCY[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
/*
*  Retrieve sub( Y )'s local information: Yii, Yjj, Yrow, Ycol
*/
   Minfog2l( IY, JY, DESCY, nprow, npcol, myrow, mycol, Yii, Yjj, Yrow, Ycol );
/*
*  Is sub( Y ) distributed or not, replicated or not ?
*/
   if( ( YisRow = ( Mupcase( YROC[0] ) == CROW ) ) != 0 )
   {
      YisD = ( ( Ycol >=  0 ) && ( npcol >  1 ) );
      YisR = ( ( Yrow == -1 ) || ( nprow == 1 ) );
   }
   else
   {
      YisD = ( ( Yrow >=  0 ) && ( nprow >  1 ) );
      YisR = ( ( Ycol == -1 ) || ( npcol == 1 ) );
   }

   Aimb = DESCA[ IMB_  ]; Ainb = DESCA[ INB_  ];
   Amb  = DESCA[ MB_   ]; Anb  = DESCA[ NB_   ];
   Arow = DESCA[ RSRC_ ]; Acol = DESCA[ CSRC_ ];

   if( Mupcase( ROWCOL[0] ) == CROW )
   {
/*
*  Want a row vector
*/
      AisR = ( ( Arow <  0 ) || ( nprow == 1 ) );
/*
*  Figure out in which process row sub( Y ) or a copy of it should be found
*/
      Arowdst = PB_Cindxg2p( KA, Aimb, Amb, Arow, Arow, nprow );

      if( YisRow && ( Mupcase( CONJUG[0] ) == CNOCONJG ) )
      {
/*
*  It is possible to reuse sub( Y ) iff sub( Y ) is already a row vector and
*  the data does not need to be conjugated.
*/
         AisD = ( ( Acol >= 0 ) && ( npcol >  1 ) );

         Yinb = DESCY[INB_]; Ynb = DESCY[NB_];
         Yinb1 = PB_Cfirstnb( N, JY, Yinb, Ynb );
/*
*  sub( Y ) is aligned with A (reuse condition) iff both operands are not
*  distributed, or both of them are distributed and start in the same process
*  column and either N is smaller than the first blocksize of sub( Y ) and A,
*  or their column blocking factors match.
*/
         if( ( !AisD && !YisD ) ||
             ( ( AisD && YisD )  &&
               ( ( Acol == Ycol ) &&
                 ( ( ( Ainb >= N     ) && ( Yinb1 >= N ) ) ||
                   ( ( Ainb == Yinb1 ) && ( Anb == Ynb ) ) ) ) ) )
         {
            Ynq = PB_Cnumroc( N, 0, Yinb1, Ynb, mycol, Ycol, npcol );
            Ymp = ( YisR ? K : ( ( myrow == Yrow ) ? K : 0 ) );
            Yld = MAX( 1, K );

            if( YisR )
            {
/*
*  If sub( Y ) is replicated, there is no need to move sub( Y ) after the
*  operation (*YAPBY = 0), and it can be reused where needed and zeroed out
*  elsewhere.
*/
               *YASUM = ( AisR ? 0 : ( nprow > 1 ) );
               *YAPBY = 0;
               Yld    = DESCY[ LLD_ ];
               if( Ynq > 0 )
               {
                  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                  if( !AisR && ( myrow != Arowdst ) )
                     TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K,
                                   &Ynq, &izero, TYPE->zero, TYPE->zero, *YAPTR,
                                   &Yld );
               }
            }
            else
            {
/*
*  sub( Y ) is not replicated, the descriptor of A may need to be modified ...
*/
               if( AisR )
               {
/*
*  If A is replicated, use only the copy in the process row where sub( Y )
*  resides -> modify DESCA !!!
*/
                  *YASUM         = 0;
                  *YAPBY         = 0;
                  Yld            = DESCY[ LLD_ ];
                  DESCA[ IMB_  ] = M;
                  DESCA[ RSRC_ ] = Yrow;
                  if( ( Ynq > 0 ) && ( Ymp > 0 ) )
                     *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
               }
               else
               {
                  if( PB_Cspan( M, 0, Aimb, Amb, Arow, nprow ) )
                  {
/*
*  Otherwise, A is not replicated, let assume in addition that it spans more
*  than one process row.
*/
                     *YASUM = ( nprow > 1 );
                     *YAPBY = 0;

                     if( myrow == Yrow )
                     {
/*
*  If sub( Y ) is not in the desired process row, send it there and zero it.
*  Otherwise, reuse it.
*/
                        Yld = DESCY[ LLD_ ];
                        if( Ynq > 0 )
                        {
                           *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                           if( Yrow != Arowdst )
                           {
                              TYPE->Cgesd2d( ctxt, K, Ynq, *YAPTR, Yld, Arowdst,
                                             mycol );
                              TYPE->Ftzpad( C2F_CHAR( ALL ),
                                            C2F_CHAR( NOCONJG ), &K, &Ynq,
                                            &izero, TYPE->zero, TYPE->zero,
                                            *YAPTR, &Yld );
                           }
                        }
                     }
                     else
                     {
/*
*  Allocate space in the other process rows and initialize to zero. If sub( Y )
*  was not in the desired process row, receive it.
*/
                        Yld = MAX( 1, K );
                        if( Ynq > 0 )
                        {
                           *YAPTR  = PB_Cmalloc( K * Ynq * TYPE->size );
                           *YAFREE = 1;
                           if( ( Yrow  != Arowdst ) && ( myrow == Arowdst ) )
                              TYPE->Cgerv2d( ctxt, K, Ynq, *YAPTR, Yld, Yrow,
                                             mycol );
                           else
                              TYPE->Ftzpad( C2F_CHAR( ALL ),
                                            C2F_CHAR( NOCONJG ), &K, &Ynq,
                                            &izero, TYPE->zero, TYPE->zero,
                                            *YAPTR, &Yld );
                        }
                     }
                  }
                  else
                  {
/*
*  A spans only one process row
*/
                     if( Yrow == Arow )
                     {
/*
*  If A and sub( Y ) resides in the same process row, things are easy.
*/
                        *YASUM = 0;
                        *YAPBY = 0;
                        Yld    = DESCY[ LLD_ ];
                        if( ( myrow == Yrow ) && ( Ynq > 0 ) )
                           *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                     }
                     else
                     {
/*
*  Otherwise, sub( Y ) resides in another process row, thus allocate zero-data
*  in process row where a copy of sub( Y ) is desired, and receive it. Set
*  *YAPBY to 1, so that this data will be added (moved) after the local
*  operation has been performed.
*/
                        *YASUM = 0;
                        *YAPBY = 1;
                        if( Ynq > 0 )
                        {
                           if( myrow == Yrow )
                           {
                              Yld    = DESCY[ LLD_ ];
                              TYPE->Cgesd2d( ctxt, K, Ynq, Mptr( Y, Yii, Yjj,
                                             Yld, TYPE->size ), Yld, Arowdst,
                                             mycol );
                           }
                           else if( myrow == Arowdst )
                           {
                              Yld     = MAX( 1, K );
                              *YAPTR  = PB_Cmalloc( K*Ynq*TYPE->size );
                              *YAFREE = 1;
                              TYPE->Cgerv2d( ctxt, K, Ynq, *YAPTR, Yld, Yrow,
                                             mycol );
                           }
                        }
                        Yrow = Arowdst;
                     }
                  }
               }
            }
/*
*  Describe the resulting operand. Note that when reduction should occur, Yrow
*  contains the destination row. Assuming every process row needs the result,
*  Yrow is then -1.
*/
            PB_Cdescset( DYA, K, N, K, Yinb1, 1, Ynb, Yrow, Ycol, ctxt, Yld );
            return;
         }
      }
/*
*  sub( Y ) cannot be reused, force YAPBY to 1 for the later update of sub( Y ).
*/
      *YAPBY = 1;
      Anq    = PB_Cnumroc( N, 0, Ainb, Anb, mycol, Acol, npcol );
      Yld    = MAX( 1, K );

      if( YisR )
      {
/*
*  If sub( Y ) is replicated, allocate space in every process row owning some
*  columns of A and initialize it to zero only where needed. There may be some
*  wasted space (suppose A was residing in just one row), however, it is hoped
*  that moving back this data to sub( Y ) will then be cheaper ...
*/
         *YASUM = ( AisR ? 0 : ( nprow > 1 ) );
         if( Anq > 0 )
         {
            *YAPTR  = PB_Cmalloc( K * Anq * TYPE->size );
            *YAFREE = 1;
            if( ( Arowdst >= 0 ) && ( myrow != Arowdst ) )
               TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K, &Anq,
                             &izero, TYPE->zero, TYPE->zero, *YAPTR, &Yld );
         }
      }
      else
      {
/*
*  sub( Y ) resides in only one process row
*/
         if( AisR )
         {
/*
*  If A is replicated, then modify sub( A ) so that only one process row will
*  compute the result before moving it back to sub( Y ).
*/
            *YASUM         = 0;
            DESCA[ IMB_  ] = M;
            if( YisRow )
            {
/*
*  Choose a different process row than Yrow for better performance (more links)
*  in the later move-back phase.
*/
               DESCA[RSRC_] = MModSub1( Yrow, nprow );
            }
            else
            {
               DESCA[RSRC_] = 0;
            }
            if( ( myrow == ( Arowdst = DESCA[RSRC_] ) ) && ( Anq > 0 ) )
            {
               *YAPTR  = PB_Cmalloc( K * Anq * TYPE->size );
               *YAFREE = 1;
            }
         }
         else
         {
            if( PB_Cspan( M, 0, Aimb, Amb, Arow, nprow ) )
            {
/*
*  If A is not replicated, and spans more than just one process row, then
*  allocate space in every process row and zero it where needed.
*/
               *YASUM = ( nprow > 1 );
               if( Anq > 0 )
               {
                  *YAPTR  = PB_Cmalloc( K * Anq * TYPE->size );
                  *YAFREE = 1;
                  if( myrow != Arowdst )
                     TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &K,
                                   &Anq, &izero, TYPE->zero, TYPE->zero, *YAPTR,
                                   &Yld );
               }
            }
            else
            {
/*
*  If A is not replicated, and spans only one process row, then allocate space
*  within that process row.
*/
               *YASUM = 0;
               if( ( myrow == Arowdst ) && ( Anq > 0 ) )
               {
                  *YAPTR  = PB_Cmalloc( K * Anq * TYPE->size );
                  *YAFREE = 1;
               }
            }
         }
      }
/*
*  Describe the resulting operand. Note that when reduction should occur,
*  Arowdst contains the destination row. Assuming every process row needs the
*  result, Arowdst is then -1.
*/
      PB_Cdescset( DYA, K, N, K, Ainb, 1, Anb, Arowdst, Acol, ctxt, Yld );
/*
*  Move sub( Y ) in the desired processes and with the correct layout
*/
      if( YisRow )
      {
         PB_Cpaxpby( TYPE, CONJUG, K, N, TYPE->one, Y, IY, JY, DESCY, ROW,
                     TYPE->zero, *YAPTR, 0, 0, DYA, ROW );
      }
      else
      {
         PB_Cpaxpby( TYPE, CONJUG, N, K, TYPE->one, Y, IY, JY, DESCY, COLUMN,
                     TYPE->zero, *YAPTR, 0, 0, DYA, ROW );
      }
   }
   else
   {
/*
*  Want a column vector with original data in col KA
*/
      AisR = ( ( Acol <  0 ) || ( npcol == 1 ) );
/*
*  Figure out in which process column sub( Y ) or a copy of it should be found.
*/
      Acoldst = PB_Cindxg2p( KA, Ainb, Anb, Acol, Acol, npcol );

      if( !( YisRow ) && ( Mupcase( CONJUG[0] ) == CNOCONJG ) )
      {
/*
*  It is possible to reuse sub( Y ) iff sub( Y ) is already a column vector and
*  the data does not need to be conjugated.
*/
         AisD = ( ( Arow >= 0 ) && ( nprow >  1 ) );

         Yimb = DESCY[IMB_]; Ymb = DESCY[MB_];
         Yimb1 = PB_Cfirstnb( M, IY, Yimb, Ymb );
/*
*  sub( Y ) is aligned with A (reuse condition) iff both operands are not
*  distributed, or both of them are distributed and start in the same process
*  row and either M is smaller than the first blocksize of sub( Y ) and A, or
*  their row blocking factors match.
*/
         if( ( !AisD && !YisD ) ||
             ( ( AisD && YisD )  &&
               ( ( Arow == Yrow ) &&
                 ( ( ( Aimb >= M     ) && ( Yimb1 >= M ) ) ||
                   ( ( Aimb == Yimb1 ) && ( Amb == Ymb ) ) ) ) ) )
         {
            Ymp = PB_Cnumroc( M, 0, Yimb1, Ymb, myrow, Yrow, nprow );
            Ynq = ( YisR ? K : ( ( mycol == Ycol ) ? K : 0 ) );
            Yld = MAX( 1, Ymp );

            if( YisR )
            {
/*
*  If sub( Y ) is replicated, there is no need to move sub( Y ) after the
*  operation (*YAPBY = 0), and it can be reused where needed and zeroed out
*  elsewhere.
*/
               *YASUM = ( AisR ? 0 : ( npcol > 1 ) );
               *YAPBY = 0;
               Yld    = DESCY[ LLD_ ];
               if( Ymp > 0 )
               {
                  *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                  if( !AisR && ( mycol != Acoldst ) )
                     TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Ymp,
                                   &K, &izero, TYPE->zero, TYPE->zero, *YAPTR,
                                   &Yld );
               }
            }
            else
            {
/*
*  sub( Y ) is not replicated, the descriptor of A may need to be modified ...
*/
               if( AisR )
               {
/*
*  If A is replicated, use only the copy in the process column where sub( Y )
*  resides -> modify DESCA !!!
*/
                  *YASUM         = 0;
                  *YAPBY         = 0;
                  Yld            = DESCY[ LLD_ ];
                  DESCA[ INB_  ] = N;
                  DESCA[ CSRC_ ] = Ycol;
                  if( ( Ymp > 0 ) && ( Ynq > 0 ) )
                     *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
               }
               else
               {
                  if( PB_Cspan( N, 0, Ainb, Anb, Acol, npcol ) )
                  {
/*
*  Otherwise, A is not replicated, let assume in addition that it spans more
*  than one process column.
*/
                     *YASUM = ( npcol > 1 );
                     *YAPBY = 0;

                     if( mycol == Ycol )
                     {
/*
*  If sub( Y ) is not in the desired process column, send it there and zero it.
*  Otherwise, reuse it.
*/
                        Yld = DESCY[ LLD_ ];
                        if( Ymp > 0 )
                        {
                           *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                           if( Ycol != Acoldst )
                           {
                              TYPE->Cgesd2d( ctxt, Ymp, K, *YAPTR, Yld, myrow,
                                             Acoldst );
                              TYPE->Ftzpad( C2F_CHAR( ALL ),
                                            C2F_CHAR( NOCONJG ), &Ymp, &K,
                                            &izero, TYPE->zero, TYPE->zero,
                                            *YAPTR, &Yld );
                           }
                        }
                     }
                     else
                     {
/*
*  Allocate space in the other process columns and initialize to zero. If
*  sub( Y ) was not in the desired process column, receive it.
*/
                        Yld = MAX( 1, Ymp );
                        if( Ymp > 0 )
                        {
                           *YAPTR  = PB_Cmalloc( Ymp * K * TYPE->size );
                           *YAFREE = 1;
                           if( ( Ycol  != Acoldst ) && ( mycol == Acoldst ) )
                              TYPE->Cgerv2d( ctxt, Ymp, K, *YAPTR, Yld, myrow,
                                             Ycol );
                           else
                              TYPE->Ftzpad( C2F_CHAR( ALL ),
                                            C2F_CHAR( NOCONJG ), &Ymp, &K,
                                            &izero, TYPE->zero, TYPE->zero,
                                            *YAPTR, &Yld );
                        }
                     }
                  }
                  else
                  {
/*
*  A spans only one process column
*/
                     if( Ycol == Acol )
                     {
/*
*  If A and sub( Y ) resides in the same process column, things are easy.
*/
                        *YASUM = 0;
                        *YAPBY = 0;
                        Yld    = DESCY[ LLD_ ];
                        if( ( mycol == Ycol ) && ( Ymp > 0 ) )
                           *YAPTR = Mptr( Y, Yii, Yjj, Yld, TYPE->size );
                     }
                     else
                     {
/*
*  Otherwise, sub( Y ) resides in another process column, thus allocate
*  zero-data in process column where a copy of sub( Y ) is desired, and receive
*  it. Set *YAPBY to 1, so that this data will be added (moved) after the local
*  operation has been performed.
*/
                        *YASUM = 0;
                        *YAPBY = 1;
                        if( Ymp > 0 )
                        {
                           if( mycol == Ycol )
                           {
                              Yld    = DESCY[ LLD_ ];
                              TYPE->Cgesd2d( ctxt, Ymp, K, Mptr( Y, Yii, Yjj,
                                             Yld, TYPE->size ), Yld, myrow,
                                             Acoldst );
                           }
                           else if( mycol == Acoldst )
                           {
                              Yld     = MAX( 1, Ymp ) ;
                              *YAPTR  = PB_Cmalloc( Ymp * K * TYPE->size );
                              *YAFREE = 1;
                              TYPE->Cgerv2d( ctxt, Ymp, K, *YAPTR, Yld, myrow,
                                             Ycol );
                           }
                        }
                        Ycol = Acoldst;
                     }
                  }
               }
            }
/*
*  Describe the resulting operand. Note that when reduction should occur, Ycol
*  contains the destination column. Assuming every process column needs the
*  result, Ycol is then -1.
*/
            PB_Cdescset( DYA, M, K, Yimb1, K, Ymb, 1, Yrow, Ycol, ctxt, Yld );
            return;
         }
      }
/*
*  sub( Y ) cannot be reused, force YAPBY to 1 for the later update of sub( Y ).
*/
      *YAPBY = 1;
      Amp = PB_Cnumroc( M, 0, Aimb, Amb, myrow, Arow, nprow );
      Yld    = MAX( 1, Amp );

      if( YisR )
      {
/*
*  If sub( Y ) is replicated, allocate space in every process column owning some
*  columns of A and initialize it to zero only where needed. There may be some
*  wasted space (suppose A was residing in just one column), however, it is
*  hoped that moving back this data to sub( Y ) will then be cheaper ...
*/
         *YASUM = ( AisR ? 0 : ( npcol > 1 ) );
         if( Amp > 0 )
         {
            *YAPTR  = PB_Cmalloc( Amp * K * TYPE->size );
            *YAFREE = 1;
            if( ( Acoldst >= 0 ) && ( mycol != Acoldst ) )
               TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp, &K,
                             &izero, TYPE->zero, TYPE->zero, *YAPTR, &Yld );
         }
      }
      else
      {
/*
*  sub( Y ) resides in only one process column
*/
         if( AisR )
         {
/*
*  If A is replicated, then modify sub( A ) so that only one process column will
*  compute the result before moving it back to sub( Y ).
*/
            *YASUM         = 0;
            DESCA[ INB_  ] = N;
            if( YisRow )
            {
               DESCA[ CSRC_ ] = 0;
            }
            else
            {
/*
*  Choose a different process column than Ycol for better performance (more
*  links) in the later move-back phase.
*/
               DESCA[ CSRC_ ] = MModSub1( Ycol, npcol );
            }
            if( ( mycol == ( Acoldst = DESCA[CSRC_] ) ) && ( Amp > 0 ) )
            {
               *YAPTR  = PB_Cmalloc( Amp * K * TYPE->size );
               *YAFREE = 1;
            }
         }
         else
         {
            if( PB_Cspan( N, 0, Ainb, Anb, Acol, npcol ) )
            {
/*
*  If A is not replicated, and spans more than just one process column, then
*  allocate space in every process column and zero it where needed.
*/
               *YASUM = ( npcol > 1 );
               if( Amp > 0 )
               {
                  *YAPTR  = PB_Cmalloc( Amp * K * TYPE->size );
                  *YAFREE = 1;
                  if( mycol != Acoldst )
                     TYPE->Ftzpad( C2F_CHAR( ALL ), C2F_CHAR( NOCONJG ), &Amp,
                                   &K, &izero, TYPE->zero, TYPE->zero, *YAPTR,
                                   &Yld );
               }
            }
            else
            {
/*
*  If A is not replicated, and spans only one process column, then allocate
*  space within that process column.
*/
               *YASUM = 0;
               if( ( mycol == Acoldst ) && ( Amp > 0 ) )
               {
                  *YAPTR  = PB_Cmalloc( Amp * K * TYPE->size );
                  *YAFREE = 1;
               }
            }
         }
      }
/*
*  Describe the resulting operand. Note that when reduction should occur,
*  Acoldst contains the destination column. Assuming every process column needs
*  the result, Acoldst is then -1.
*/
      PB_Cdescset( DYA, M, K, Aimb, K, Amb, 1, Arow, Acoldst, ctxt, Yld );
/*
*  Move sub( Y ) in the desired processes and with the correct layout
*/
      if( YisRow )
      {
         PB_Cpaxpby( TYPE, CONJUG, K, M, TYPE->one, Y, IY, JY, DESCY, ROW,
                     TYPE->zero, *YAPTR, 0, 0, DYA, COLUMN );
      }
      else
      {
         PB_Cpaxpby( TYPE, CONJUG, M, K, TYPE->one, Y, IY, JY, DESCY, COLUMN,
                     TYPE->zero, *YAPTR, 0, 0, DYA, COLUMN );
      }
   }
/*
*  End of PB_CInOutV2
*/
}