root / src / pgesv / HPL_logsort.c
Historique | Voir | Annoter | Télécharger (7,59 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_logsort
|
54 |
( |
55 |
const int NPROCS, |
56 |
const int ICURROC, |
57 |
int * IPLEN,
|
58 |
int * IPMAP,
|
59 |
int * IPMAPM1
|
60 |
) |
61 |
#else
|
62 |
void HPL_logsort
|
63 |
( NPROCS, ICURROC, IPLEN, IPMAP, IPMAPM1 ) |
64 |
const int NPROCS; |
65 |
const int ICURROC; |
66 |
int * IPLEN;
|
67 |
int * IPMAP;
|
68 |
int * IPMAPM1;
|
69 |
#endif
|
70 |
{ |
71 |
/*
|
72 |
* Purpose
|
73 |
* =======
|
74 |
*
|
75 |
* HPL_logsort computes an array IPMAP and its inverse IPMAPM1 that
|
76 |
* contain the logarithmic sorted processes id with repect to the local
|
77 |
* number of rows of U that they own. This is necessary to ensure that
|
78 |
* the logarithmic spreading of U is optimal in terms of number of steps
|
79 |
* and communication volume as well. In other words, the larget pieces
|
80 |
* of U will be sent a minimal number of times.
|
81 |
*
|
82 |
* Arguments
|
83 |
* =========
|
84 |
*
|
85 |
* NPROCS (global input) const int
|
86 |
* On entry, NPROCS specifies the number of process rows in the
|
87 |
* process grid. NPROCS is at least one.
|
88 |
*
|
89 |
* ICURROC (global input) const int
|
90 |
* On entry, ICURROC is the source process row.
|
91 |
*
|
92 |
* IPLEN (global input/output) int *
|
93 |
* On entry, IPLEN is an array of dimension NPROCS+1, such that
|
94 |
* IPLEN[0] is 0, and IPLEN[i] contains the number of rows of U,
|
95 |
* that process i-1 has. On exit, IPLEN[i] is the number of
|
96 |
* rows of U in the processes before process IPMAP[i] after the
|
97 |
* sort, with the convention that IPLEN[NPROCS] is the total
|
98 |
* number of rows of the panel. In other words, IPLEN[i+1] -
|
99 |
* IPLEN[i] is the number of rows of A that should be moved to
|
100 |
* the process IPMAP[i]. IPLEN is such that the number of rows
|
101 |
* of the source process row is IPLEN[1] - IPLEN[0], and the
|
102 |
* remaining entries of this array are sorted so that the
|
103 |
* quantities IPLEN[i+1]-IPLEN[i] are logarithmically sorted.
|
104 |
*
|
105 |
* IPMAP (global output) int *
|
106 |
* On entry, IPMAP is an array of dimension NPROCS. On exit,
|
107 |
* array contains the logarithmic mapping of the processes. In
|
108 |
* other words, IPMAP[myroc] is the corresponding sorted process
|
109 |
* coordinate.
|
110 |
*
|
111 |
* IPMAPM1 (global output) int *
|
112 |
* On entry, IPMAPM1 is an array of dimension NPROCS. On exit,
|
113 |
* this array contains the inverse of the logarithmic mapping
|
114 |
* contained in IPMAP: IPMAPM1[ IPMAP[i] ] = i, for all i in
|
115 |
* [0.. NPROCS)
|
116 |
*
|
117 |
* ---------------------------------------------------------------------
|
118 |
*/
|
119 |
/*
|
120 |
* .. Local Variables ..
|
121 |
*/
|
122 |
int dist, i, ip, iplen_i, iplen_j, itmp, j, k;
|
123 |
/* ..
|
124 |
* .. Executable Statements ..
|
125 |
*/
|
126 |
/*
|
127 |
* Compute the logarithmic distance between process j and process 0, as
|
128 |
* well as the maximum logarithmic distance. IPMAPM1 is workarray here.
|
129 |
*/
|
130 |
for( j = 0, dist = 0; j < NPROCS; j++ ) |
131 |
{ |
132 |
IPMAP[j] = MModAdd( j, ICURROC, NPROCS ); ip = j; itmp = 0;
|
133 |
do { if( ip & 1 ) itmp++; ip >>= 1; } while ( ip ); |
134 |
IPMAPM1[j] = itmp; if( itmp > dist ) dist = itmp;
|
135 |
} |
136 |
/*
|
137 |
* Shift IPLEN[1..NPROCS] of ICURROC places, so that IPLEN[1] is now
|
138 |
* what used to be IPLEN[ICURROC+1]. Initialize IPMAP, so that IPMAP[0]
|
139 |
* is ICURROC.
|
140 |
*/
|
141 |
for( j = 0; j < ICURROC; j++ ) |
142 |
{ |
143 |
for( i = 2, itmp = IPLEN[1]; i <= NPROCS; i++ ) IPLEN[i-1] = IPLEN[i]; |
144 |
IPLEN[NPROCS] = itmp; |
145 |
} |
146 |
/*
|
147 |
* logarithmic sort
|
148 |
*/
|
149 |
for( k = 1; k <= dist; k++ ) |
150 |
{ |
151 |
for( j = 1; j < NPROCS; j++ ) |
152 |
{ |
153 |
if( IPMAPM1[j] == k )
|
154 |
{ |
155 |
for( i = 2; i < NPROCS; i++ ) |
156 |
{ |
157 |
if( k < IPMAPM1[i] )
|
158 |
{ |
159 |
iplen_i = IPLEN[i+1]; iplen_j = IPLEN[j+1]; |
160 |
|
161 |
if( iplen_j < iplen_i )
|
162 |
{ |
163 |
IPLEN[j+1] = iplen_i; IPLEN[i+1] = iplen_j; |
164 |
itmp = IPMAP[j]; IPMAP[j] = IPMAP[i]; |
165 |
IPMAP[i] = itmp; |
166 |
} |
167 |
} |
168 |
} |
169 |
} |
170 |
} |
171 |
} |
172 |
/*
|
173 |
* Compute IPLEN and IPMAPM1 (the inverse of IPMAP)
|
174 |
*/
|
175 |
IPLEN[0] = 0; |
176 |
|
177 |
for( i = 0; i < NPROCS; i++ ) |
178 |
{ |
179 |
IPMAPM1[ IPMAP[i] ] = i; |
180 |
IPLEN[i+1] += IPLEN[i];
|
181 |
} |
182 |
/*
|
183 |
* End of HPL_logsort
|
184 |
*/
|
185 |
} |