CBLAS的使用例程

#include <stdio.h>
#include <time.h>
#include <malloc.h>
#include <process.h>
//完成矩阵乘法,注意BLAS中数组存放要按照列主序
// 包含着五个文件,相当于包含了lib文件
extern"C"
{
#include <blaswrap.h>
#include <f2c.h>
#include <clapack.h>
#include <fblaswr.h>
#include <cblas.h>
}


#define SIZE_M 2//定义被计算数组1行数
#define SIZE_N 2//定义被计算数组1列数
#define SIZE_J  2//定义数组2行
#define SIZE_K 2//定义数组2列

#define DATA_IN1_R "d://MATLAB7/work/cmat_A_r.txt"//the real part of a matrix(3,2)
#define DATA_IN1_I "d://MATLAB7/work/cmat_A_i.txt"//the imaginary part of a martix(3,2)

#define DATA_IN2_R "d://MATLAB7/work/cmat_B_r.txt"//the real part of a matrix(3,2)
#define DATA_IN2_I "d://MATLAB7/work/cmat_B_i.txt"//the imaginary part of a martix(3,2)




int main(void)
{

	integer m = SIZE_M;
	integer n = SIZE_N;
	integer j = SIZE_J;
	integer k = SIZE_K;

	
	char transa = 'N';
	char transb = 'N';
        doublecompe a[4] = {{0.00043,0.4343},{1.0,0.0},{1.232,9.323},{32.32,43.434}};
        doublecompe b[4] = {{0.00043,0.4343},{1.0,0.0},{1.232,9.323},{32.32,43.434}};

  doublecomplex *c__;doublecomplex alpha = {1.0,0.0};integer lda = m;integer ldb = j;integer ldc = m;
integer ii;
 // integer info_fileread1;// integer info_fileread2;//a = (doublecomplex *) calloc ( m * n, sizeof(doublecomplex) ); //开辟空间,其实只是测试不用,我是需要读入非常大的数组//b = (doublecomplex *) calloc ( j * k, sizeof(doublecomplex) );c__ = (doublecomplex *) calloc ( m * k, sizeof(doublecomplex) );

 //fileread_doublecomplex1( DATA_IN1_R, DATA_IN1_I, m, n, a, &info_fileread1);//该处为我自己的读入文件数据函数,你可以直赋值来测试// fileread_doublecomplex1( DATA_IN2_R, DATA_IN2_I, j, k, b, &info_fileread2);// printf("\nfileread1 = %ld\nfileread2 = %ld",info_fileread1,info_fileread2);zgemm_( &transa, &transb, &m, &k, &j, &alpha, a, &lda, b, &ldb, &alpha, c__, &ldc); // print_matrix_doublecomplex( m, k, c__);

for( ii =0; i<4;i++)
{
printf("\n%lf %+lfi", c__[ii].r,c__[ii].i);
}


free(c__);

  system("pause");return 0;}以下为函数zgemm_()函数的说明/*  Purpose       =======       ZGEMM  performs one of the matrix-matrix operations          C := alpha*op( A )*op( B ) + beta*C,       where  op( X ) is one of          op( X ) = X   or   op( X ) = X'   or   op( X ) = conjg( X' ),       alpha and beta are scalars, and A, B and C are matrices, with op( A )       an m by k matrix,  op( B )  a  k by n matrix and  C an m by n matrix.       Arguments       ==========       TRANSA - CHARACTER*1.                On entry, TRANSA specifies the form of op( A ) to be used in                the matrix multiplication as follows:                   TRANSA = 'N' or 'n',  op( A ) = A.                   TRANSA = 'T' or 't',  op( A ) = A'.                   TRANSA = 'C' or 'c',  op( A ) = conjg( A' ).                Unchanged on exit.       TRANSB - CHARACTER*1.                On entry, TRANSB specifies the form of op( B ) to be used in                the matrix multiplication as follows:                   TRANSB = 'N' or 'n',  op( B ) = B.                   TRANSB = 'T' or 't',  op( B ) = B'.                   TRANSB = 'C' or 'c',  op( B ) = conjg( B' ).                Unchanged on exit.       M      - INTEGER.                On entry,  M  specifies  the number  of rows  of the  matrix                op( A )  and of the  matrix  C.  M  must  be at least  zero.                Unchanged on exit.       N      - INTEGER.                On entry,  N  specifies the number  of columns of the matrix                op( B ) and the number of columns of the matrix C. N must be                at least zero.                Unchanged on exit.       K      - INTEGER.                On entry,  K  specifies  the number of columns of the matrix                op( A ) and the number of rows of the matrix op( B ). K must                be at least  zero.                Unchanged on exit.       ALPHA  - COMPLEX*16      .                On entry, ALPHA specifies the scalar alpha.                Unchanged on exit.       A      - COMPLEX*16       array of DIMENSION ( LDA, ka ), where ka is                k  when  TRANSA = 'N' or 'n',  and is  m  otherwise.                Before entry with  TRANSA = 'N' or 'n',  the leading  m by k                part of the array  A  must contain the matrix  A,  otherwise                the leading  k by m  part of the array  A  must contain  the                matrix A.                Unchanged on exit.       LDA    - INTEGER.                On entry, LDA specifies the first dimension of A as declared                in the calling (sub) program. When  TRANSA = 'N' or 'n' then                LDA must be at least  max( 1, m ), otherwise  LDA must be at                least  max( 1, k ).                Unchanged on exit.       B      - COMPLEX*16       array of DIMENSION ( LDB, kb ), where kb is                n  when  TRANSB = 'N' or 'n',  and is  k  otherwise.                Before entry with  TRANSB = 'N' or 'n',  the leading  k by n                part of the array  B  must contain the matrix  B,  otherwise                the leading  n by k  part of the array  B  must contain  the                matrix B.                Unchanged on exit.       LDB    - INTEGER.                On entry, LDB specifies the first dimension of B as declared                in the calling (sub) program. When  TRANSB = 'N' or 'n' then                LDB must be at least  max( 1, k ), otherwise  LDB must be at                least  max( 1, n ).                Unchanged on exit.       BETA   - COMPLEX*16      .                On entry,  BETA  specifies the scalar  beta.  When  BETA  is                supplied as zero then C need not be set on input.                Unchanged on exit.       C      - COMPLEX*16       array of DIMENSION ( LDC, n ).                Before entry, the leading  m by n  part of the array  C must                contain the matrix  C,  except when  beta  is zero, in which                case C need not be set on entry.                On exit, the array  C  is overwritten by the  m by n  matrix                ( alpha*op( A )*op( B ) + beta*C ).       LDC    - INTEGER.                On entry, LDC specifies the first dimension of C as declared                in  the  calling  (sub)  program.   LDC  must  be  at  least                max( 1, m ).                Unchanged on exit.    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值