68 lines
1.2 KiB
C++
68 lines
1.2 KiB
C++
#include <cassert>
|
|
#include <chrono> // timing
|
|
#include <cmath> // sqrt()
|
|
#include <cstdlib> // atoi()
|
|
#include <cstring> // strncmp()
|
|
#include <ctime>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <lapacke.h>
|
|
|
|
using namespace std;
|
|
using namespace std::chrono; // timing
|
|
|
|
int main()
|
|
{
|
|
unsigned int n= 10;
|
|
unsigned int nhrs = 1;
|
|
|
|
vector<double> M(n*n,4.0);
|
|
|
|
for(unsigned int i=0; i<n; i++)
|
|
{
|
|
for(unsigned int j=0; j<n; j++)
|
|
{
|
|
if(i!=j)
|
|
{
|
|
double diff = i-j;
|
|
M[i*n+j] = 1.0/(diff*diff);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vector<int> ipiv(n); //pivots
|
|
LAPACKE_dgetrf(LAPACK_ROW_MAJOR,n,n, M.data(),n,ipiv.data()); //M=PLU
|
|
|
|
|
|
unsigned int runtimes[] = {1,2,4,8,16,32};
|
|
|
|
for(unsigned int i=0; i < 6;i++)
|
|
{
|
|
nhrs = runtimes[i];
|
|
vector<double> b(n*nhrs,0.0);
|
|
for (unsigned int j=0; j<n; j++)
|
|
{
|
|
for (unsigned int k=0; k<nhrs; k++)
|
|
{
|
|
b[j*nhrs+k] = j*nhrs+k;
|
|
}
|
|
}
|
|
LAPACKE_dgetrs(LAPACK_ROW_MAJOR,'N',n,nhrs,M.data(),n,ipiv.data(),b.data(),nhrs);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|