lapack_test.c
#include <stdio.h>
extern void dgesv_(int *N, int *NRHS, double *A, int *LDA, int * IPIV, double *B, int *LDB, int * INFO);
#define D 4
#define DB 2
int main()
{
FILE *out;
double CA[D][D], A[D*D],
CB[D][DB], B[D*DB] ;
int N, NRHS, IPIV[D], INFO;
int i, j;
N = D;
NRHS = 2;
CA[0][0]=1, CA[0][1]=4, CA[0][2]=-2, CA[0][3]=3;
CA[1][0]=2, CA[1][1]=2, CA[1][2]= 0, CA[1][3]=4;
CA[2][0]=3, CA[2][1]=0, CA[2][2]=-1, CA[2][3]=2;
CA[3][0]=1, CA[3][1]=2, CA[3][2]= 2, CA[3][3]=-3;
CB[0][0]=6, CB[0][1]=1;
CB[1][0]=2, CB[1][1]=2;
CB[2][0]=1, CB[2][1]=3;
CB[3][0]=8, CB[3][1]=4;
for(i=0; i< D; i++)
for(j=0;j<D; j++)
A[i + D*j] = CA[i][j];
for(i=0; i<D; i++)
for(j=0;j<NRHS; j++)
B[i+D*j] = CB[i][j];
dgesv_(&N, &NRHS, A, &N, IPIV, B, &N, &INFO);
out = stderr;
fprintf(out, "INFO: %d\n", INFO);
fprintf(out, "A:\n");
for(i=0;i<D; i++)
{
for(j=0;j<D; j++)
fprintf(out, "%g\t", A[i+D*j]);
fprintf(out, "\n");
}
fprintf(out, "B:\n");
for(i=0;i<D; i++)
{
for(j=0;j<NRHS; j++)
fprintf(out, "%g\t", B[i+D*j]);
fprintf(out, "\n");
}
return 0;
}
lapack_test.f
program Console1
external dgesv
integer n, lda, nrhs, ldb
parameter (n=2,lda=2,nrhs=1,ldb=2)
double precision A(lda,n)
double precision b(ldb,nrhs)
character byebye
integer ipiv(n), info, i, j
A(1,1)=1
A(1,2)=2
A(2,1)=3
A(2,2)=4
B(1,1)=5
B(2,1)=6
write(*,*) 'Hello World'
call dgesv(n,nrhs,A,lda,ipiv,b,ldb,info)
write(*,*) 'INFO =', info
write(*,*) ((A(i,j),i=1,lda),j=1,n)
write(*,*) ((B(i,j),i=1,ldb),j=1,nrhs)
write(*,*) "END OF PROGRAM..."
end program Console1
这两个代码还没有进一步学习。其大致的执行命令为
gfortran test_lapack.f -lblas -llapack
ok就先放在这里。