From 783a88f8904b5758195f96c65c7e0b6e87f8a51e Mon Sep 17 00:00:00 2001 From: cnlohr Date: Sat, 17 Mar 2018 01:00:07 -0400 Subject: Update DCLapack with the C helpers to cize stuff. --- redist/dclapack.h | 78 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 31 deletions(-) (limited to 'redist/dclapack.h') diff --git a/redist/dclapack.h b/redist/dclapack.h index 4e209d3..62f3e9d 100644 --- a/redist/dclapack.h +++ b/redist/dclapack.h @@ -1,10 +1,6 @@ #ifndef __DCLAPACK_H__ #define __DCLAPACK_H__ -#ifndef ORDER -#define ORDER 50 -#endif - #ifndef FLOAT #define FLOAT float #endif @@ -13,6 +9,13 @@ #define _ABS(a) ( (a)<=0 ? 0-(a) : (a) ) +#ifdef DYNAMIC_INDEX + #define _(A,O,P) A[O*n+P] +#else + #define _(A,O,P) A[O][P] +#endif + + /* * Prints a matrix A (n by m) */ @@ -21,7 +24,7 @@ printf(#A "\n"); \ for (i=0; i _ABS(U[max][i])) { max = j; } \ + if (_ABS( _(U,j,i)) > _ABS(_(U,max,i))) { max = j; } \ } \ _tempi=Piv[i]; Piv[i]=Piv[max]; Piv[max]=_tempi; \ for (k=i; k=0; j--) { \ float sum=0.0; \ - for (k=n-1; k>j; k--) { sum += U[j][k]*X[k][i]; } \ - X[j][i] = (B[j][i] - sum) / U[j][j]; \ + for (k=n-1; k>j; k--) { sum += _(U,j,k)*_(X,k,i); } \ + _(X,j,i) = (_(B,j,i) - sum) / _(U,j,j); \ } \ } \ } @@ -140,12 +143,25 @@ /* * Inverts a matrix X (n by n) using the method of LU decomposition */ -#define INV(A,Ainv,n) { \ + +#ifdef DYNAMIC_INDEX + #define INV_SETUP(ORDER) \ + FLOAT Ipiv[ORDER*ORDER]; \ + FLOAT L[ORDER*ORDER]; \ + FLOAT U[ORDER*ORDER]; \ + FLOAT I[ORDER*ORDER]; \ + FLOAT C[ORDER*ORDER]; +#else + #define INV_SETUP(ORDER) \ FLOAT Ipiv[ORDER][ORDER]; \ FLOAT L[ORDER][ORDER]; \ FLOAT U[ORDER][ORDER]; \ FLOAT I[ORDER][ORDER]; \ - FLOAT C[ORDER][ORDER]; \ + FLOAT C[ORDER][ORDER]; +#endif + +#define INV(A,Ainv,n,ORDER) { \ + INV_SETUP(ORDER) \ int Piv[ORDER]; \ IDENTITY(I,n); \ LU(A,L,U,Piv,n); \ @@ -174,9 +190,9 @@ PRINT(Ainv,n,n); \ int i,j,k; \ for (i=0; i