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 ++++++++++++++++++++++++++++++++--------------------- redist/dclhelpers.c | 63 +++++++++++++++++++++++++++++++++++++++++++ redist/dclhelpers.h | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 31 deletions(-) create mode 100644 redist/dclhelpers.c create mode 100644 redist/dclhelpers.h (limited to 'redist') 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 +#include "dclapack.h" + + +void dclPrint( const DCL_FLOAT * A, int n, int m ) +{ + PRINT( A, n, m ); +} + +void dclIdentity( DCL_FLOAT * A, int n ) +{ + IDENTITY( A, n ); +} + +void dclTransp( const DCL_FLOAT * A, DCL_FLOAT * B, int n, int m) +{ + TRANSP(A,B,n,m); +} + +void dclLU( const DCL_FLOAT * A, DCL_FLOAT * L, DCL_FLOAT * U, int * Piv, int n ) +{ + LU(A,L,U,Piv,n); +} + +void dclPivot( const DCL_FLOAT * A, DCL_FLOAT * B, int * Piv, int n, int m ) +{ + PIVOT(A,B,Piv,n,m); +} + +void dclLSub( const DCL_FLOAT * L, DCL_FLOAT * X, const DCL_FLOAT * B, int n, int m ) +{ + L_SUB(L,X,B,n,m); +} + +void dclUSub( const DCL_FLOAT * U, DCL_FLOAT * X, const DCL_FLOAT * B, int n, int m ) +{ + U_SUB(U,X,B,n,m); +} + +void dclInv( const DCL_FLOAT * A, DCL_FLOAT * Ainv, int n ) +{ + INV(A,Ainv,n,n); +} + +void dclMul( const DCL_FLOAT * A, const DCL_FLOAT * B, DCL_FLOAT * C, int n, int m, int p ) +{ + MUL(A,B,C,n,m,p); +} + +void dclMulAdd( const DCL_FLOAT * A, const DCL_FLOAT * B, const DCL_FLOAT * C, DCL_FLOAT * D, int n, int m, int p ) +{ + MULADD(A,B,C,D,n,m,p); +} + +void dclGMulAdd( const DCL_FLOAT * A, const DCL_FLOAT * B, const DCL_FLOAT * C, DCL_FLOAT * D, DCL_FLOAT alpha, DCL_FLOAT beta, int n, int m, int p ) +{ + GMULADD(A,B,C,D,alpha,beta,n,m,p); +} + + diff --git a/redist/dclhelpers.h b/redist/dclhelpers.h new file mode 100644 index 0000000..fbaa7ec --- /dev/null +++ b/redist/dclhelpers.h @@ -0,0 +1,61 @@ +#ifndef _DCL_HELPERS_H +#define _DCL_HELPERS_H + +#define DCL_FLOAT FLT + +//XXX XXX XXX WARNING XXX XXX XXX The argument order may be changing!!! + +/* Prints matrix A of size[n][m] */ +void dclPrint( const DCL_FLOAT * A, int n, int m ); + +/* Returns the identity matrix */ +void dclIdentity( DCL_FLOAT * A, int n ); + +/* B = Transpose(A) + A is (n by m) + B is (m by n) */ +void dclTransp( const DCL_FLOAT * A, DCL_FLOAT * B, int n, int m ); + +/* Calculate L,U of a matrix A with pivot table; the pivot table is output. */ +void dclLU( const DCL_FLOAT * A, DCL_FLOAT * L, DCL_FLOAT * U, int * Piv, int n ); + +/* Pivots a matrix to a different matrix + B = Pivot(A) given table 'Piv' + A and B are (n by m) */ +void dclPivot( const DCL_FLOAT * A, DCL_FLOAT * B, int * Piv, int n, int m ); + +/* Solve LX=B for matrix X and B + L is n by n (lower triangular) + B is n by m */ +void dclLSub( const DCL_FLOAT * L, DCL_FLOAT * X, const DCL_FLOAT * B, int n, int m ); + +/* Solve UX=B for matrix X and B + U is n by n (upper triangular) + B is n by m */ +void dclUSub( const DCL_FLOAT * U, DCL_FLOAT * X, const DCL_FLOAT * B, int n, int m ); + +/* Inverts a matrix X (n by n) using the method of LU decomposition */ +void dclInv( const DCL_FLOAT * A, DCL_FLOAT * Ainv, int n ); + +/* Matrix Multiply C = A * B + A (n by m) + B (m by p) + C (n by p) */ +void dclMul( const DCL_FLOAT * A, const DCL_FLOAT * B, DCL_FLOAT * C, int n, int m, int p ); + +/* Matrix Multiply D = A * B + C + A (n by m) + B (m by p) + C (n by p) + D (n by p) */ +void dclMulAdd( const DCL_FLOAT * A, const DCL_FLOAT * B, const DCL_FLOAT * C, DCL_FLOAT * D, int n, int m, int p ); + +/* Matrix Multiply D = alpha * A * B + beta * C + A (n by m) + B (m by p) + C (n by p) + D (n by p) */ +void dclGMulAdd( const DCL_FLOAT * A, const DCL_FLOAT * B, const DCL_FLOAT * C, DCL_FLOAT * D, DCL_FLOAT alpha, DCL_FLOAT beta, int n, int m, int p ); + +#endif + -- cgit v1.2.3