sheet3
This commit is contained in:
parent
0b93cbcdd3
commit
56614805cf
12 changed files with 4496 additions and 0 deletions
68
sheet3/7/main.cpp
Normal file
68
sheet3/7/main.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
#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;
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue