Ex8 and minor improvements
This commit is contained in:
parent
2195a9db0a
commit
77bc8c6aa3
50 changed files with 214845 additions and 43 deletions
43
sheet3/7/benchmark.cpp
Normal file
43
sheet3/7/benchmark.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
#include <cblas.h>
|
||||
|
||||
// Inner product
|
||||
double benchmark_A(const vector<double> &x, const vector<double> &y)
|
||||
{
|
||||
|
||||
|
||||
return cblas_ddot(x.size(),x.data(),1,y.data(),1);
|
||||
|
||||
}
|
||||
|
||||
//Matrix-vector product
|
||||
vector<double> benchmark_B(const vector<double> &A, const vector<double> &x)
|
||||
{
|
||||
unsigned int N = x.size();
|
||||
unsigned int M = A.size() / N;
|
||||
vector<double> b(M, 0.0);
|
||||
|
||||
cblas_dgemv(CblasRowMajor,CblasNoTrans,M,N,1,A.data(),N,x.data(),1,0.0,b.data(),1);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
//Matrix-Matrix product
|
||||
vector<double> benchmark_C(const vector<double> &A, const vector<double> &B, unsigned int M)
|
||||
{
|
||||
unsigned int L = A.size()/M;
|
||||
unsigned int N = B.size()/L;
|
||||
vector<double> C(M*N,0.0);
|
||||
|
||||
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,M,N,L,1.0,A.data(),L,B.data(),N,0.0,C.data(),N);
|
||||
|
||||
return C;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue