root / src / pauxil / HPL_indxg2lp.c @ 1
Historique | Voir | Annoter | Télécharger (7,71 ko)
1 |
/*
|
---|---|
2 |
* -- High Performance Computing Linpack Benchmark (HPL)
|
3 |
* HPL - 2.0 - September 10, 2008
|
4 |
* Antoine P. Petitet
|
5 |
* University of Tennessee, Knoxville
|
6 |
* Innovative Computing Laboratory
|
7 |
* (C) Copyright 2000-2008 All Rights Reserved
|
8 |
*
|
9 |
* -- Copyright notice and Licensing terms:
|
10 |
*
|
11 |
* Redistribution and use in source and binary forms, with or without
|
12 |
* modification, are permitted provided that the following conditions
|
13 |
* are met:
|
14 |
*
|
15 |
* 1. Redistributions of source code must retain the above copyright
|
16 |
* notice, this list of conditions and the following disclaimer.
|
17 |
*
|
18 |
* 2. Redistributions in binary form must reproduce the above copyright
|
19 |
* notice, this list of conditions, and the following disclaimer in the
|
20 |
* documentation and/or other materials provided with the distribution.
|
21 |
*
|
22 |
* 3. All advertising materials mentioning features or use of this
|
23 |
* software must display the following acknowledgement:
|
24 |
* This product includes software developed at the University of
|
25 |
* Tennessee, Knoxville, Innovative Computing Laboratory.
|
26 |
*
|
27 |
* 4. The name of the University, the name of the Laboratory, or the
|
28 |
* names of its contributors may not be used to endorse or promote
|
29 |
* products derived from this software without specific written
|
30 |
* permission.
|
31 |
*
|
32 |
* -- Disclaimer:
|
33 |
*
|
34 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
35 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
36 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
37 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
|
38 |
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
39 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
40 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
41 |
* DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
42 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
43 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
44 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
45 |
* ---------------------------------------------------------------------
|
46 |
*/
|
47 |
/*
|
48 |
* Include files
|
49 |
*/
|
50 |
#include "hpl.h" |
51 |
|
52 |
#ifdef STDC_HEADERS
|
53 |
void HPL_indxg2lp
|
54 |
( |
55 |
int * IL,
|
56 |
int * PROC,
|
57 |
const int IG, |
58 |
const int INB, |
59 |
const int NB, |
60 |
const int SRCPROC, |
61 |
const int NPROCS |
62 |
) |
63 |
#else
|
64 |
void HPL_indxg2lp
|
65 |
( IL, PROC, IG, INB, NB, SRCPROC, NPROCS ) |
66 |
int * IL;
|
67 |
int * PROC;
|
68 |
const int IG; |
69 |
const int INB; |
70 |
const int NB; |
71 |
const int SRCPROC; |
72 |
const int NPROCS; |
73 |
#endif
|
74 |
{ |
75 |
/*
|
76 |
* Purpose
|
77 |
* =======
|
78 |
*
|
79 |
* HPL_indxg2lp computes the local index of a matrix entry pointed to by
|
80 |
* the global index IG as well as the process coordinate which posseses
|
81 |
* this entry. The local returned index is the same in all processes.
|
82 |
*
|
83 |
* Arguments
|
84 |
* =========
|
85 |
*
|
86 |
* IL (output) int *
|
87 |
* On exit, IL specifies the local index corresponding to IG. IL
|
88 |
* is at least zero.
|
89 |
*
|
90 |
* PROC (output) int *
|
91 |
* On exit, PROC is the coordinate of the process owning the
|
92 |
* entry specified by the global index IG. PROC is at least zero
|
93 |
* and less than NPROCS.
|
94 |
*
|
95 |
* IG (input) const int
|
96 |
* On entry, IG specifies the global index of the matrix entry.
|
97 |
* IG must be at least zero.
|
98 |
*
|
99 |
* INB (input) const int
|
100 |
* On entry, INB specifies the size of the first block of the
|
101 |
* global matrix. INB must be at least one.
|
102 |
*
|
103 |
* NB (input) const int
|
104 |
* On entry, NB specifies the blocking factor used to partition
|
105 |
* and distribute the matrix A. NB must be larger than one.
|
106 |
*
|
107 |
* SRCPROC (input) const int
|
108 |
* On entry, if SRCPROC = -1, the data is not distributed but
|
109 |
* replicated, in which case this routine returns IG in all
|
110 |
* processes. Otherwise, the value of SRCPROC is ignored.
|
111 |
*
|
112 |
* NPROCS (input) const int
|
113 |
* On entry, NPROCS specifies the total number of process rows
|
114 |
* or columns over which the matrix is distributed. NPROCS must
|
115 |
* be at least one.
|
116 |
*
|
117 |
* ---------------------------------------------------------------------
|
118 |
*/
|
119 |
/*
|
120 |
* .. Local Variables ..
|
121 |
*/
|
122 |
int i, j;
|
123 |
/* ..
|
124 |
* .. Executable Statements ..
|
125 |
*/
|
126 |
if( ( IG < INB ) || ( SRCPROC == -1 ) || ( NPROCS == 1 ) ) |
127 |
{ |
128 |
/*
|
129 |
* IG belongs to the first block, or the data is not distributed, or
|
130 |
* there is just one process in this dimension of the grid.
|
131 |
*/
|
132 |
*IL = IG; |
133 |
*PROC = SRCPROC; |
134 |
} |
135 |
else
|
136 |
{ |
137 |
/*
|
138 |
* IG = INB - NB + ( l * NPROCS + MYROC ) * NB + X with 0 <= X < NB,
|
139 |
* thus IG is to be found in the block (IG-INB+NB) / NB = l*NPROCS+MYROC
|
140 |
* with 0 <= MYROC < NPROCS. The local index to be returned depends on
|
141 |
* whether IG resides in the process owning the first partial block of
|
142 |
* size INB (MYROC=0). To determine this cheaply, let i = (IG-INB) / NB,
|
143 |
* so that if NPROCS divides i+1, i.e. MYROC=0, we have i+1 = l*NPROCS.
|
144 |
* If we set j = i / NPROCS, it follows that j = l-1. Therefore, i+1 is
|
145 |
* equal to (j+1) * NPROCS. Conversely, if NPROCS does not divide i+1,
|
146 |
* then i+1 = l*NPROCS + MYROC with 1 <= MYROC < NPROCS. It follows that
|
147 |
* j=l and thus (j+1)*NPROCS > i+1.
|
148 |
*/
|
149 |
j = ( i = ( IG - INB ) / NB ) / NPROCS; |
150 |
/*
|
151 |
* IG is in block 1 + ( IG - INB ) / NB. Add this to SRCPROC and take
|
152 |
* the NPROCS modulo (definition of the block-cyclic data distribution).
|
153 |
*/
|
154 |
*PROC = SRCPROC + 1 + i;
|
155 |
*PROC = MPosMod( *PROC, NPROCS ); |
156 |
/*
|
157 |
* When IG resides in the process owning the first partial block of size
|
158 |
* INB (MYROC = 0), then the result IL can be written as:
|
159 |
* IL = INB - NB + l * NB + X = IG + ( l - (l * NPROCS + MYROC) ) * NB.
|
160 |
* Using the above notation, we have i+1 = l*NPROCS + MYROC = l*NPROCS,
|
161 |
* i.e l = ( i+1 ) / NPROCS = j+1, since NPROCS divides i+1, therefore
|
162 |
* IL = IG + ( j + 1 - ( i + 1 ) ) * NB.
|
163 |
*
|
164 |
* Otherwise when MYROC >= 1, the result IL can be written as:
|
165 |
* IL = l * NB + X = IG - INB + ( ( l+1 ) - ( l * NPROCS + MYROC ) )*NB.
|
166 |
* We still have i+1 = l*NPROCS+MYROC. Since NPROCS does not divide i+1,
|
167 |
* we have j = (l*NPROCS+MYROC-1) / NPROCS = l, i.e
|
168 |
* IL = IG - INB + ( j + 1 - ( i + 1 ) ) * NB.
|
169 |
*/
|
170 |
*IL = NB * (j - i) + |
171 |
( ( i + 1 - ( j + 1 )*NPROCS ) ? IG - INB : IG ); |
172 |
} |
173 |
/*
|
174 |
* End of HPL_indxg2lp
|
175 |
*/
|
176 |
} |