File: PB_Cnpreroc.c

package info (click to toggle)
scalapack 1.8.0-12
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,712 kB
  • ctags: 29,423
  • sloc: fortran: 288,069; ansic: 64,035; makefile: 1,966
file content (154 lines) | stat: -rw-r--r-- 5,233 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
/* ---------------------------------------------------------------------
*
*  -- 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__
int PB_Cnpreroc( int N, int I, int INB, int NB, int PROC, int SRCPROC,
                 int NPROCS )
#else
int PB_Cnpreroc( N, I, INB, NB, PROC, SRCPROC, NPROCS )
/*
*  .. Scalar Arguments ..
*/
   int            I, INB, N, NB, NPROCS, PROC, SRCPROC;
#endif
{
/*
*  Purpose
*  =======
*
*  PB_Cnpreroc computes  the  number of preceeding rows or columns of a
*  submatrix  that  are  possessed by processes closer to SRCPROC1 than
*  PROC where SRCPROC1 is the process owning the row or column globally
*  indexed by I. The submatrix is defined by giving out N  rows/columns
*  starting from global index I.  Therefore, if  SRCPROC=0 and  PROC=4,
*  then PB_Cnpreroc returns the number of matrix rows or columns  owned
*  by processes 0, 1, 2, and 3.
*
*  Arguments
*  =========
*
*  N       (global input) INTEGER
*          On entry, N  specifies the number of rows/columns being dealt
*          out. N must be at least zero.
*
*  I       (global input) INTEGER
*          On entry, I  specifies the global index of the matrix  entry.
*          I must be at least zero.
*
*  INB     (global input) INTEGER
*          On entry,  INB  specifies  the size of the first block of the
*          global matrix distribution. INB must be at least one.
*
*  NB      (global input) INTEGER
*          On entry, NB specifies the size of the blocks used to  parti-
*          tion the matrix. NB must be at least one.
*
*  PROC    (local input) INTEGER
*          On entry, PROC specifies  the coordinate of the process whose
*          local portion is determined.  PROC must be at least zero  and
*          strictly less than NPROCS.
*
*  SRCPROC (global input) INTEGER
*          On entry,  SRCPROC  specifies  the coordinate of the  process
*          that possesses the  first row or column  of the matrix.  When
*          SRCPROC = -1, the data  is not  distributed  but  replicated,
*          otherwise  SRCPROC  must be at least zero and  strictly  less
*          than NPROCS.
*
*  NPROCS  (global input) INTEGER
*          On entry,  NPROCS  specifies the total number of process rows
*          or columns over which the matrix is distributed.  NPROCS must
*          be at least one.
*
*  -- Written on April 1, 1998 by
*     Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
*  ---------------------------------------------------------------------
*/
/*
*  .. Local Scalars ..
*/
   int            ilocblk, mydist, nblocks;
/* ..
*  .. Executable Statements ..
*
*/
   if( ( SRCPROC == -1 ) || ( NPROCS == 1 ) )
/*
*  The data is not distributed, or there is just one process in this dimension
*  of the grid.
*/
      return( 0 );
/*
*  Compute coordinate of process owning I and corresponding INB
*/
   if( ( INB -= I ) <= 0 )
   {
/*
*  I is not in first block, find out which process has it and update size of
*  first block
*/
      nblocks  = ( -INB ) / NB + 1;
      SRCPROC += nblocks;
      SRCPROC -= ( SRCPROC / NPROCS ) * NPROCS;
      INB     += nblocks * NB;
   }
/*
*  Now everything is just like N, I=0, INB, NB, SRCPROC, NPROCS. If I am the
*  source process, nothing preceeds me ...
*/
   if( PROC == SRCPROC ) return( 0 );
/*
*  If SRCPROC owns the N rows or columns, then return N since I cannot be the
*  source process anymore.
*/
   if( N <= INB ) return( N );
/*
*  Find out how many full blocks are globally (nblocks) and locally (ilocblk)
*  in those N entries.
*/
   nblocks = ( N - INB ) / NB + 1;
/*
*  Compute my distance from the source process so that within this process
*  coordinate system, the source process is the process such that mydist=0.
*/
   if( ( mydist = PROC - SRCPROC ) < 0 ) mydist += NPROCS;
/*
*  When mydist < nblocks - ilocblk * NPROCS, I own ilocblk + 1 full blocks,
*  when mydist > nblocks - ilocblk * NPROCS, I own ilocblk     full blocks,
*  when mydist = nblocks - ilocblk * NPROCS, either the last block is not full
*  and I own it, or the last block is full and I am the first process owning
*  only ilocblk full blocks.
*
*  Therefore, when 0 < mydist <= nblocks - ilocblk * NPROCS, the number of rows
*  or columns preceeding me is INB + ilocblk*NB + (mydist-1)*(ilocblk+1)*NB,
*  i.e. INB - NB + ( ilocblk+1 ) * NB * mydist. Otherwise, there are exactly
*  NB * ilocblk * ( NPROCS - mydist ) rows or columns after me including mine,
*  i.e N + NB * ilocblk * ( mydist - NPROCS ) rows or columns preceeding me.
*/
   if( nblocks < NPROCS )
      return( ( ( mydist <= nblocks ) ? INB + NB * ( mydist - 1 ) : N ) );

   ilocblk = nblocks / NPROCS;
   return( ( ( mydist <= ( nblocks - ilocblk * NPROCS ) ) ?
             INB - NB + ( ilocblk + 1 ) * NB * mydist :
             N + NB * ilocblk * ( mydist - NPROCS ) ) );
/*
*  End of PB_Cnpreroc
*/
}