Statistiques
| Révision :

root / src / pgesv / HPL_spreadN.c @ 1

Historique | Voir | Annoter | Télécharger (12,54 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_spreadN
54
(
55
   HPL_T_panel *                    PBCST,
56
   int *                            IFLAG,
57
   HPL_T_panel *                    PANEL,
58
   const enum HPL_SIDE              SIDE,
59
   const int                        N,
60
   double *                         U,
61
   const int                        LDU,
62
   const int                        SRCDIST,
63
   const int *                      IPLEN,
64
   const int *                      IPMAP,
65
   const int *                      IPMAPM1
66
)
67
#else
68
void HPL_spreadN
69
( PBCST, IFLAG, PANEL, SIDE, N, U, LDU, SRCDIST, IPLEN, IPMAP, IPMAPM1 )
70
   HPL_T_panel *                    PBCST;
71
   int *                            IFLAG;
72
   HPL_T_panel *                    PANEL;
73
   const enum HPL_SIDE              SIDE;
74
   const int                        N;
75
   double *                         U;
76
   const int                        LDU;
77
   const int                        SRCDIST;
78
   const int *                      IPLEN;
79
   const int *                      IPMAP;
80
   const int *                      IPMAPM1;
81
#endif
82
{
83
/* 
84
 * Purpose
85
 * =======
86
 *
87
 * HPL_spreadN spreads the local array containing local pieces of U, so
88
 * that on exit to this function,  a piece of  U  is contained in every
89
 * process row. The array IPLEN contains the number of rows of U,  that
90
 * should be spread on any given process row. This function also probes
91
 * for the presence of the column panel PBCST. In case of success, this
92
 * panel will be forwarded.  If  PBCST  is NULL on input,  this probing
93
 * mechanism will be disabled.
94
 *
95
 * Arguments
96
 * =========
97
 *
98
 * PBCST   (local input/output)          HPL_T_panel *
99
 *         On entry,  PBCST  points to the data structure containing the
100
 *         panel (to be broadcast) information.
101
 *
102
 * IFLAG   (local input/output)          int *
103
 *         On entry, IFLAG  indicates  whether or not  the broadcast has
104
 *         already been completed.  If not,  probing will occur, and the
105
 *         outcome will be contained in IFLAG on exit.
106
 *
107
 * PANEL   (local input/output)          HPL_T_panel *
108
 *         On entry,  PANEL  points to the data structure containing the
109
 *         panel (to be spread) information.
110
 *
111
 * SIDE    (global input)                const enum HPL_SIDE
112
 *         On entry, SIDE specifies whether the local piece of U located
113
 *         in process IPMAP[SRCDIST] should be spread to the right or to
114
 *         the left. This feature is used by the equilibration process.
115
 *
116
 * N       (global input)                const int
117
 *         On entry,  N  specifies  the  local number of columns of U. N
118
 *         must be at least zero.
119
 *
120
 * U       (local input/output)          double *
121
 *         On entry,  U  is an array of dimension (LDU,*) containing the
122
 *         local pieces of U.
123
 *
124
 * LDU     (local input)                 const int
125
 *         On entry, LDU specifies the local leading dimension of U. LDU
126
 *         should be at least MAX(1,IPLEN[nprow]).
127
 *
128
 * SRCDIST (local input)                 const int
129
 *         On entry,  SRCDIST  specifies the source process that spreads
130
 *         its piece of U.
131
 *
132
 * IPLEN   (global input)                const int *
133
 *         On entry, IPLEN is an array of dimension NPROW+1.  This array
134
 *         is such that IPLEN[i+1] - IPLEN[i] is the number of rows of U
135
 *         in each process before process IPMAP[i], with the  convention
136
 *         that IPLEN[nprow] is the total number of rows. In other words
137
 *         IPLEN[i+1] - IPLEN[i]  is  the local number of rows of U that
138
 *         should be moved to process IPMAP[i].
139
 *
140
 * IPMAP   (global input)                const int *
141
 *         On entry, IPMAP is an array of dimension  NPROW.  This  array
142
 *         contains  the  logarithmic mapping of the processes. In other
143
 *         words, IPMAP[myrow]  is the absolute coordinate of the sorted
144
 *         process.
145
 *
146
 * IPMAPM1 (global input)                const int *
147
 *         On entry,  IPMAPM1 is an array of dimension NPROW. This array
148
 *         contains  the inverse of the logarithmic mapping contained in
149
 *         IPMAP: For i in [0.. NPROW) IPMAPM1[IPMAP[i]] = i.
150
 *
151
 * ---------------------------------------------------------------------
152
 */ 
153
/*
154
 * .. Local Variables ..
155
 */
156
   MPI_Datatype              type;
157
   MPI_Status                status;
158
   MPI_Comm                  comm;
159
   unsigned int              ip2=1, mask=1, mydist, mydist2;
160
   int                       Cmsgid=MSGID_BEGIN_PFACT, ibuf,
161
                             ierr=MPI_SUCCESS, il, k, lbuf, lgth, myrow,
162
                             npm1, nprow, partner;
163
/* ..
164
 * .. Executable Statements ..
165
 */
166
   myrow = PANEL->grid->myrow;    nprow = PANEL->grid->nprow;
167
   comm  = PANEL->grid->col_comm;
168
/*
169
 * Spread U to the left
170
 */
171
   if( SIDE == HplLeft )
172
   {
173
      nprow = ( npm1 = SRCDIST ) + 1;
174
      if( ( ( mydist = (unsigned int)(IPMAPM1[myrow]) ) >
175
              (unsigned int)(SRCDIST) ) || ( npm1 == 0 ) ) return;
176

    
177
      k = npm1; while( k > 1 ) { k >>= 1; ip2 <<= 1; mask <<= 1; mask++; }
178
      mydist2 = ( mydist = npm1 - mydist ); il = npm1 - ip2;
179
      lgth    = IPLEN[nprow];
180

    
181
      do
182
      {
183
         mask ^= ip2;
184

    
185
         if( ( mydist & mask ) == 0 )
186
         {
187
            lbuf = IPLEN[il+1] - ( ibuf = IPLEN[il-Mmin(il, (int)(ip2))] ); 
188

    
189
            if( lbuf > 0 )
190
            {
191
               partner = mydist ^ ip2;
192

    
193
               if( mydist & ip2 )
194
               {
195
                  if( ierr == MPI_SUCCESS )  
196
                     ierr =   MPI_Type_vector( N, lbuf, LDU, MPI_DOUBLE,
197
                                               &type );
198
                  if( ierr == MPI_SUCCESS )  
199
                     ierr =   MPI_Type_commit( &type );
200
                  if( ierr == MPI_SUCCESS )  
201
                     ierr =   MPI_Recv( Mptr( U, ibuf, 0, LDU ), 1, type,
202
                                        IPMAP[npm1-partner], Cmsgid, comm,
203
                                        &status );
204
                  if( ierr == MPI_SUCCESS )  
205
                     ierr =   MPI_Type_free(   &type );
206
               }
207
               else if( partner < nprow )
208
               {
209
                  if( ierr == MPI_SUCCESS )  
210
                     ierr =   MPI_Type_vector( N, lbuf, LDU, MPI_DOUBLE,
211
                                               &type );
212
                  if( ierr == MPI_SUCCESS )  
213
                     ierr =   MPI_Type_commit( &type );
214
                  if( ierr == MPI_SUCCESS )  
215
                     ierr =   MPI_Send( Mptr( U, ibuf, 0, LDU ), 1, type,
216
                                        IPMAP[npm1-partner], Cmsgid, comm );
217
                  if( ierr == MPI_SUCCESS )  
218
                     ierr =   MPI_Type_free(   &type );
219
               }
220
            }
221
         }
222
 
223
         if( mydist2 < ip2 ) {  ip2 >>= 1; il += ip2; }
224
         else { mydist2 -= ip2; ip2 >>= 1; il -= ip2; }
225
/*
226
 * Probe for column panel - forward it when available
227
 */
228
         if( *IFLAG == HPL_KEEP_TESTING ) (void) HPL_bcast( PBCST, IFLAG );
229
 
230
      } while( ip2 > 0 );
231
   }
232
   else
233
   {
234
      npm1 = ( nprow -= SRCDIST ) - 1;
235
      if( ( ( mydist = (unsigned int)(IPMAPM1[myrow]) ) <
236
              (unsigned int)(SRCDIST) ) || ( npm1 == 0 ) ) return;
237

    
238
      k = npm1; while( k > 1 ) { k >>= 1; ip2 <<= 1; mask <<= 1; mask++; }
239
      mydist2 = ( mydist -= SRCDIST ); il = ip2;
240
      lgth    = IPLEN[SRCDIST+nprow];
241
/*
242
 * Spread U to the right - offset the IPLEN, and IPMAP arrays
243
 */
244
      do
245
      {
246
         mask ^= ip2;
247

    
248
         if( ( mydist & mask ) == 0 )
249
         {
250
            k    = il + ip2; ibuf = IPLEN[SRCDIST+il];
251
            lbuf = ( k >= nprow ? lgth : IPLEN[SRCDIST+k] ) - ibuf;
252

    
253
            if( lbuf > 0 )
254
            {
255
               partner = mydist ^ ip2;
256

    
257
               if( mydist & ip2 )
258
               {
259
                  if( ierr == MPI_SUCCESS )  
260
                     ierr =   MPI_Type_vector( N, lbuf, LDU, MPI_DOUBLE,
261
                                               &type );
262
                  if( ierr == MPI_SUCCESS )  
263
                     ierr =   MPI_Type_commit( &type );
264
                  if( ierr == MPI_SUCCESS )  
265
                     ierr =   MPI_Recv( Mptr( U, ibuf, 0, LDU ), 1, type,
266
                                        IPMAP[SRCDIST+partner], Cmsgid,
267
                                        comm, &status );
268
                  if( ierr == MPI_SUCCESS )  
269
                     ierr =   MPI_Type_free(   &type );
270
               }
271
               else if( partner < nprow )
272
               {
273
                  if( ierr == MPI_SUCCESS )  
274
                     ierr =   MPI_Type_vector( N, lbuf, LDU, MPI_DOUBLE,
275
                                               &type );
276
                  if( ierr == MPI_SUCCESS )  
277
                     ierr =   MPI_Type_commit( &type );
278
                  if( ierr == MPI_SUCCESS )  
279
                     ierr =   MPI_Send( Mptr( U, ibuf, 0, LDU ), 1, type,
280
                                        IPMAP[SRCDIST+partner], Cmsgid,
281
                                        comm );
282
                  if( ierr == MPI_SUCCESS )  
283
                     ierr =   MPI_Type_free(   &type );
284
               }
285
            }
286
         }
287
 
288
         if( mydist2 < ip2 ) {  ip2 >>= 1; il -= ip2; }
289
         else { mydist2 -= ip2; ip2 >>= 1; il += ip2; }
290
/*
291
 * Probe for column panel - forward it when available
292
 */
293
         if( *IFLAG == HPL_KEEP_TESTING ) (void) HPL_bcast( PBCST, IFLAG );
294
 
295
      } while( ip2 > 0 );
296
   }
297

    
298
   if( ierr != MPI_SUCCESS )
299
   { HPL_pabort( __LINE__, "HPL_spreadN", "MPI call failed" ); }
300
/*
301
 * End of HPL_spreadN
302
 */
303
}