应用Clapack计算逆矩阵

#include <iostream>
using namespace std;
#include "blaswrap.h"
#include "f2c.h"

#include "MatrixCal.h"
#include <time.h>


inline unsigned __int64 GetCycleCount()
{
__asm _emit 0x0F
__asm _emit 0x31
}

int main()
{
 integer Dimension = 1000;

 cout<<"Input Matrix Dimension:"<<endl;

 cin>>Dimension;

 integer M = Dimension;

 srand( (unsigned)time(NULL));

 real * a = new real [Dimension*Dimension];

 cout<<"Matrix Dimension is "<<Dimension <<"*"<<Dimension<<endl;

// cout<<"Random Matrix is generated as follows:"<<endl;

 for (int i1 = 0; i1 < Dimension; i1 ++)
 {
  for (int i2 = 0; i2 < Dimension; i2 ++)
  {
   a[i1*Dimension+i2] = double(rand())/RAND_MAX;
//   cout<<a[i1*Dimension+i2]<<"  ";
  }
//  cout<<endl;
 }
 real * c = new real[Dimension*Dimension];

    integer lda = M;
    integer lwork = Dimension;
    integer INFO;

    integer * ipiv = new integer[Dimension*Dimension];
 
// unsigned long t;
// t = (unsigned long)GetCycleCount();

 clock_t start, finish;

 start = clock();
 
 sgetrf_(&M,&M,a,&M,ipiv,&INFO);

 sgetri_(&M,a,&lda,ipiv,c,&lwork,&INFO);

 finish = clock() - start;

 cout<<"Elapsed time is:"<<finish<<" ms"<<endl;


// t -= (unsigned long)GetCycleCount();
//
// double Time = t/(2.8*1000000000);
//
// cout<<"Elapsed time is:"<<Time<<" seconds"<<endl;
// cout<<"Elapsed time is:"<<t<<" cycle"<<endl;


// cout<<"The invert Matrix is as follows:"<<endl; 
 
 
    if(INFO==0)
    {
  for (int i3 = 0; i3 < Dimension; i3 ++)
  {
   for (int i4 = 0; i4 < Dimension; i4 ++)
   {
//    cout<<a[i3*Dimension+i4]<<"  ";
   }
//   cout<<endl;
  }
    }
    else
    {
       cout<<"Failed."<<endl;
    } 

 delete []a;
 delete []c;
 delete []ipiv;
    return 0;
}

 

 

#ifndef _MATRIXCAL_H
#define _MATRIXCAL_H

#include "blaswrap.h"
#include "f2c.h"

#include "sgetri.c"
#include "strtri.c"
#include "strti2.c"
#include "strmv.c"
#include "strsm.c"
#include "strmm.c"
#include "sswap.c"
#include "sgemm.c"
#include "sgemv.c"
#include "sscal.c"
#include "ieeeck.c"
#include "F77_aloc.c"
#include "sgetrf.c"
#include "slaswp.c"
#include "sgetf2.c"
#include "sger.c"
#include "isamax.c"

 

#include "util/ilaenv.c"
#include "util/xerbla.c"
#include "util/lsame.c"
//#include "util/dsecnd.c"


#include "s_cmp.c"
#include "s_copy.c"
#include "s_cat.c"
#include "exit_.c"


#endif 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值