Ex8 and minor improvements

This commit is contained in:
Markus Schmidt 2025-11-12 02:04:18 +01:00
commit 77bc8c6aa3
50 changed files with 214845 additions and 43 deletions

View file

@ -8,17 +8,17 @@
#include <sstream>
#include <vector>
#include <lapacke.h>
#include "timing.h"
#include "benchmark.h"
using namespace std;
using namespace std::chrono; // timing
int main()
{
unsigned int n= 10;
unsigned int nhrs = 1;
unsigned int n= 32;
vector<double> M(n*n,4.0);
for(unsigned int i=0; i<n; i++)
{
for(unsigned int j=0; j<n; j++)
@ -32,30 +32,77 @@ int main()
}
vector<double> M2 = M;
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++)
double time;
unsigned int nhrsmax = 1000000;
for(unsigned int i=nhrsmax/10; i < nhrsmax;i+=nhrsmax/10)
{
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);
}
unsigned int nhrs = i;
//FOR CHECKING
vector<double> X(n*nhrs,1.0);
vector<double> b = benchmark_C(M2,X,n);
tic();
LAPACKE_dgetrs(LAPACK_ROW_MAJOR,'N',n,nhrs,M.data(),n,ipiv.data(),b.data(),nhrs);
time = toc();
cout << "Time for nhrs=" << nhrs << ": " << time << endl;
double max_err = 0.0;
for (unsigned int j = 0; j < n * nhrs; j++)
{
double err = b[j] - X[j];
err *= err;
if (err > max_err) max_err = err;
}
cout <<"max err^2:" << max_err <<endl;
cout <<endl;
}
/*
Time for nhrs=100000: 0.0605495
max err^2:4.93038e-32
Time for nhrs=200000: 0.127608
max err^2:4.93038e-32
Time for nhrs=300000: 0.182197
max err^2:4.93038e-32
Time for nhrs=400000: 0.202608
max err^2:4.93038e-32
Time for nhrs=500000: 0.24484
max err^2:4.93038e-32
Time for nhrs=600000: 0.298055
max err^2:4.93038e-32
Time for nhrs=700000: 0.362414
max err^2:4.93038e-32
Time for nhrs=800000: 0.410004
max err^2:4.93038e-32
Time for nhrs=900000: 0.492339
max err^2:4.93038e-32
Time grows slow (linearly)
*/