Statistiques
| Révision :

root / src / pgesv / HPL_perm.c @ 8

Historique | Voir | Annoter | Télécharger (5,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
void HPL_perm
54
(
55
   const int                        N,
56
   int *                            LINDXA,
57
   int *                            LINDXAU,
58
   int *                            IWORK
59
)
60
#else
61
void HPL_perm
62
( N, LINDXA, LINDXAU, IWORK )
63
   const int                        N;
64
   int *                            LINDXA;
65
   int *                            LINDXAU;
66
   int *                            IWORK;
67
#endif
68
{
69
/* 
70
 * Purpose
71
 * =======
72
 *
73
 * HPL_perm combines  two  index  arrays  and generate the corresponding
74
 * permutation. First, this function computes the inverse of LINDXA, and
75
 * then combine it with LINDXAU.  Second, in order to be able to perform
76
 * the permutation in place,  LINDXAU  is overwritten by the sequence of
77
 * permutation  producing  the  same result.  What we ultimately want to
78
 * achieve is:  U[LINDXAU[i]] := U[LINDXA[i]] for i in [0..N). After the
79
 * call to this function,  this in place permutation can be performed by
80
 * for i in [0..N) swap U[i] with U[LINDXAU[i]].
81
 *
82
 * Arguments
83
 * =========
84
 *
85
 * N       (global input)                const int
86
 *         On entry,  N  specifies the length of the arrays  LINDXA  and
87
 *         LINDXAU. N should be at least zero.
88
 *
89
 * LINDXA  (global input/output)         int *
90
 *         On entry,  LINDXA  is an array of dimension N  containing the
91
 *         source indexes. On exit,  LINDXA  contains the combined index
92
 *         array.
93
 *
94
 * LINDXAU (global input/output)         int *
95
 *         On entry,  LINDXAU is an array of dimension N  containing the
96
 *         target indexes.  On exit,  LINDXAU  contains  the sequence of
97
 *         permutation,  that  should be applied  in increasing order to
98
 *         permute the underlying array U in place.
99
 *
100
 * IWORK   (workspace)                   int *
101
 *         On entry, IWORK is a workarray of dimension N.
102
 *
103
 * ---------------------------------------------------------------------
104
 */ 
105
/*
106
 * .. Local Variables ..
107
 */
108
   int                        i, j, k, fndd;
109
/* ..
110
 * .. Executable Statements ..
111
 */
112
/*
113
 * Inverse LINDXA - combine LINDXA and LINDXAU - Initialize IWORK
114
 */
115
   for( i = 0; i < N; i++ ) { IWORK[LINDXA[i]] = i; }
116
   for( i = 0; i < N; i++ ) { LINDXA[i] = LINDXAU[IWORK[i]]; IWORK[i] = i; }
117
 
118
   for( i = 0; i < N; i++ )
119
   {
120
      /* search LINDXA such that    LINDXA[j]  == i */
121
      j = 0; do { fndd = ( LINDXA[j] == i ); j++; } while( !fndd ); j--;
122
      /* search IWORK  such that    IWORK[k]   == j */
123
      k = 0; do { fndd = ( IWORK[k]  == j ); k++; } while( !fndd ); k--;
124
      /* swap IWORK[i] and IWORK[k]; LINDXAU[i] = k */
125
      j = IWORK[i]; IWORK[i] = IWORK[k]; IWORK[k] = j;
126
      LINDXAU[i] = k;
127
   }
128
/*
129
 * End of HPL_perm
130
 */
131
}