Statistiques
| Révision :

root / src / pauxil / HPL_indxg2l.c @ 1

Historique | Voir | Annoter | Télécharger (6,84 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
int HPL_indxg2l
54
(
55
   const int                        IG,
56
   const int                        INB,
57
   const int                        NB,
58
   const int                        SRCPROC,
59
   const int                        NPROCS
60
)
61
#else
62
int HPL_indxg2l
63
( IG, INB, NB, SRCPROC, NPROCS )
64
   const int                        IG;
65
   const int                        INB;
66
   const int                        NB;
67
   const int                        SRCPROC;
68
   const int                        NPROCS;
69
#endif
70
{
71
/* 
72
 * Purpose
73
 * =======
74
 *
75
 * HPL_indxg2l computes  the local index of a matrix entry pointed to by
76
 * the  global index IG.  This  local  returned index is the same in all
77
 * processes.
78
 *
79
 * Arguments
80
 * =========
81
 *
82
 * IG      (input)                       const int
83
 *         On entry, IG specifies the global index of the matrix  entry.
84
 *         IG must be at least zero.
85
 *
86
 * INB     (input)                       const int
87
 *         On entry,  INB  specifies  the size of the first block of the
88
 *         global matrix. INB must be at least one.
89
 *
90
 * NB      (input)                       const int
91
 *         On entry,  NB specifies the blocking factor used to partition
92
 *         and distribute the matrix. NB must be larger than one.
93
 *
94
 * SRCPROC (input)                       const int
95
 *         On entry, if SRCPROC = -1, the data  is not  distributed  but
96
 *         replicated,  in  which  case  this  routine returns IG in all
97
 *         processes. Otherwise, the value of SRCPROC is ignored.
98
 *
99
 * NPROCS  (input)                       const int
100
 *         On entry,  NPROCS  specifies the total number of process rows
101
 *         or columns over which the matrix is distributed.  NPROCS must
102
 *         be at least one.
103
 *
104
 * ---------------------------------------------------------------------
105
 */ 
106
/*
107
 * .. Local Variables ..
108
 */
109
   int                        i, j;
110
/* ..
111
 * .. Executable Statements ..
112
 */
113
   if( ( IG < INB ) || ( SRCPROC == -1 ) || ( NPROCS == 1 ) )
114
/*
115
 * IG  belongs  to the first block,  or the data is not distributed,  or
116
 * there is just one process in this dimension of the grid.
117
 */
118
      return( IG );
119
/*
120
 * IG  =  INB - NB + ( l * NPROCS + MYROC ) * NB + X  with  0 <= X < NB,
121
 * thus IG is to be found in the block (IG-INB+NB) / NB = l*NPROCS+MYROC
122
 * with  0 <= MYROC < NPROCS.  The local index to be returned depends on 
123
 * whether  IG  resides in the process owning the first partial block of
124
 * size INB (MYROC=0). To determine this cheaply, let i = (IG-INB) / NB,
125
 * so that if NPROCS divides i+1, i.e. MYROC=0,  we have i+1 = l*NPROCS.
126
 * If we set  j = i / NPROCS, it follows that j = l-1. Therefore, i+1 is
127
 * equal to (j+1) * NPROCS.  Conversely, if NPROCS does not divide  i+1, 
128
 * then i+1 = l*NPROCS + MYROC with 1 <= MYROC < NPROCS. It follows that
129
 * j=l and thus (j+1)*NPROCS > i+1.
130
 */
131
   j = ( i = ( IG - INB ) / NB ) / NPROCS;
132
/*
133
 * When IG resides in the process owning the first partial block of size
134
 * INB (MYROC = 0), then the result IL can be written as:
135
 * IL = INB - NB + l * NB + X  = IG + ( l - (l * NPROCS + MYROC) ) * NB.
136
 * Using the above notation,  we have i+1 = l*NPROCS + MYROC = l*NPROCS,
137
 * i.e l = ( i+1 ) / NPROCS = j+1,  since  NPROCS divides i+1, therefore
138
 * IL = IG + ( j + 1 - ( i + 1 ) ) * NB.
139
 *
140
 * Otherwise when MYROC >= 1, the result IL can be written as:
141
 * IL = l * NB + X = IG - INB + ( ( l+1 ) - ( l * NPROCS + MYROC ) )*NB.
142
 * We still have i+1 = l*NPROCS+MYROC. Since NPROCS does not divide i+1,
143
 * we have j = (l*NPROCS+MYROC-1) / NPROCS = l, i.e
144
 * IL = IG - INB + ( j + 1 - ( i + 1 ) ) * NB.
145
 */
146
   return( NB * (j - i) + 
147
           ( ( i + 1 - ( j + 1 )*NPROCS ) ? IG - INB : IG ) );
148
/*
149
 * End of HPL_indxg2l
150
 */
151
}