#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