PIPS
comp_matrice.c File Reference
#include <stdio.h>
#include <math.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "effects.h"
#include "complexity_ri.h"
#include "ri-util.h"
#include "effects-util.h"
#include "misc.h"
#include "matrice.h"
#include "complexity.h"
+ Include dependency graph for comp_matrice.c:

Go to the source code of this file.

Macros

#define A(i, j)   a[n*i + j]
 comp_matrice.c More...
 
#define Y(i, j)   y[n*i + j]
 Added by AP, March 23rd 93: allows the simulation of a two-dimensional array with a mono-dimensional memory allocation. More...
 

Functions

void lu_decomposition (float *a, int n, int *indx, int *pd)
 comp_matrice.c More...
 
void lu_back_substitution (float *a, int n, int *indx, float *b)
 
void float_matrice_inversion (float *a, int n, int *indx, int *pd)
 

Macro Definition Documentation

◆ A

#define A (   i,
 
)    a[n*i + j]

comp_matrice.c

matrice inversion for floating point. 20 Oct. 92 L. Zhou

void lu_decomposition(a, n, indx, pd) Given an NxN matrix A, with physical dimension NP, here we give NP the value MAX_CONTROLS_IN_UNSTRUCTURED ( that is 100 ) this routine replaces it by the LU decomposition of a rowwise permutation of itself. A and N are input, A is output INDX is output vector which recoreds the row permutation effected by the partial pivoting; D is out put as +- 1 depending on whether the number of row interchanges was even or odd, respectively.

void lu_back_substitution(a, n, indx, b) Added by AP, March 15th 93

Definition at line 63 of file comp_matrice.c.

◆ Y

#define Y (   i,
 
)    y[n*i + j]

Added by AP, March 23rd 93: allows the simulation of a two-dimensional array with a mono-dimensional memory allocation.

Definition at line 196 of file comp_matrice.c.

Function Documentation

◆ float_matrice_inversion()

void float_matrice_inversion ( float *  a,
int  n,
int indx,
int pd 
)

set up identity matrix

Parameters
indxndx
pdd

Definition at line 198 of file comp_matrice.c.

203 {
204  int i,j;
205  float *y = (float *) malloc(sizeof(float) * n * n);
206 
207  /* set up identity matrix */
208  for (i=0; i<n; i++ ) {
209  for ( j=0; j<n; j++ )
210  Y(i,j) = 0.0;
211  Y(i,i) = 1.0;
212  }
213 
214  lu_decomposition(a, n, indx, pd);
215 
216  for ( j=0; j<n; j++ ) {
217  lu_back_substitution(a, n, indx, &(Y(j,0)) );
218  }
219  for ( j=0; j<n; j++ )
220  for ( i=0; i<n; i++ )
221  A(i,j) = Y(j,i);
222 }
#define Y(i, j)
Added by AP, March 23rd 93: allows the simulation of a two-dimensional array with a mono-dimensional ...
Definition: comp_matrice.c:196
void lu_decomposition(float *a, int n, int *indx, int *pd)
comp_matrice.c
Definition: comp_matrice.c:65
void lu_back_substitution(float *a, int n, int *indx, float *b)
Definition: comp_matrice.c:155
#define A(i, j)
comp_matrice.c
Definition: comp_matrice.c:63
void * malloc(YYSIZE_T)

References A, lu_back_substitution(), lu_decomposition(), malloc(), and Y.

Referenced by unstructured_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lu_back_substitution()

void lu_back_substitution ( float *  a,
int  n,
int indx,
float *  b 
)

back substitution

Parameters
indxndx

Definition at line 155 of file comp_matrice.c.

160 {
161  int i,j;
162  int ii = -1;
163  float sum;
164  int ll;
165 
166  for (i=0; i<n; i++ ) {
167  ll = indx[i];
168  sum = b[ll];
169  b[ll] = b[i];
170  if ( ii != -1 ) {
171  for ( j=ii; j<=i-1; j++ ) {
172  sum = sum -A(i,j)*b[j];
173  }
174  }
175  else if ( sum != 0.0 ) {
176  ii = i;
177  }
178  b[i] = sum;
179  }
180 
181  /* back substitution */
182  for ( i=n-1; i>=0; i-- ) {
183  sum = b[i];
184  if ( i < n ) {
185  for ( j=i+1; j < n; j++ ) {
186  sum = sum - A(i,j)*b[j];
187  }
188  }
189  b[i] = sum/A(i,i);
190  }
191 }
t_real sum(int n1, int n2, int n3, t_real u[n1][n2][n3])
Definition: stencil.c:57

References A, and sum().

Referenced by float_matrice_inversion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lu_decomposition()

void lu_decomposition ( float *  a,
int  n,
int indx,
int pd 
)

comp_matrice.c

Added by AP, March 15th 93

If using gcc to compile, vv can be declared as vv[n] LZ 29/10/92 float vv[n];

loop over rows to get the implicit scaling information

loopover columns of Crout's method

Parameters
aModif by AP, March 15th 93 float a[n][n]; int indx[n];
indxndx
pdd

Definition at line 65 of file comp_matrice.c.

76 {
77  float aamax;
78 
79 /* Added by AP, March 15th 93 */
81 /* If using gcc to compile, vv can be declared as vv[n] LZ 29/10/92
82  float vv[n];
83 */
84 
85  int i,j,k;
86  float sum,dum;
87  int imax = 0;
88  float tiny = 0.000001;
89 
90  *pd = 1;
91 
92  /* loop over rows to get the implicit scaling information */
93  for (i=0; i<n; i++ ) {
94  aamax = 0.0;
95  for ( j=0; j<n; j++) {
96  if ( fabs(A(i,j)) > aamax ) {
97  aamax = fabs(A(i,j));
98  }
99  }
100 
101  if ( aamax == 0.0 ) {
102  fprintf(stderr, "Singular matrix -- No non-zero element\n");
103  user_error("lu_decomposition", "Module does not terminate\n");
104  }
105  vv[i] = 1./aamax;
106  }
107 
108  /* loopover columns of Crout's method */
109  for ( j=0; j<n; j++ ) {
110  for ( i=0; i<=j-1; i++ ) {
111  sum = A(i,j);
112  for ( k=0; k<i; k++) {
113  sum = sum - A(i,k)*A(k,j);
114  }
115  A(i,j) = sum;
116  }
117 
118  aamax = 0.0;
119 
120  for ( i=j; (i<n) ; i++ ) {
121  sum = A(i,j);
122  for ( k=0; k<j; k++ ) {
123  sum = sum - A(i,k)*A(k,j);
124  }
125  A(i,j) = sum;
126  dum = vv[i]*fabs(sum);
127  if ( dum >= aamax ) {
128  imax = i;
129  aamax = dum;
130  }
131  }
132 
133  if ( j != imax ) {
134  for ( k=0; k<n; k++ ) {
135  dum = A(imax,k);
136  A(imax,k) = A(j,k);
137  A(j,k) = dum;
138  }
139  *pd = - *pd;
140  vv[imax] = vv[j];
141  }
142 
143  indx[j] = imax;
144  if ( A(j,j) == 0.0 )
145  A(j,j) = tiny;
146  if ( j != n-1 ) {
147  dum = 1./A(j,j);
148  for ( i=j+1; i<n; i++ ) {
149  A(i,j) = A(i,j)*dum;
150  }
151  }
152  }
153 }
#define MAX_CONTROLS_IN_UNSTRUCTURED
#define user_error(fn,...)
Definition: misc-local.h:265
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...

References A, fprintf(), MAX_CONTROLS_IN_UNSTRUCTURED, sum(), and user_error.

Referenced by float_matrice_inversion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: