I wrote a very simple vector class to call level 1 BLAS through MKL,
#include<mkl.h>
#include<stdexcept>
#ifndef _x_matrix
#define _x_matrix
class xVec{
private:
double *v;
int n;
public:
xVec():n(0),v(0){}
xVec(int a):n(a),v(new double[n]){}
xVec(int a, double c){
n=a;
v=new double[n];
for(int i=0; i<n; ++i) v[i]=c;
}
~xVec(){if(v) delete[]v;}
double &operator()(int i){
if(i<n) return v[i];
else throw runtime_error("Out of boundary.");
}
double asum(int incx=1){
// return sum v by incx
return dasum(&n, v, &incx);
}
};
Then,
const int n(100);
xVec x(n,10););
cout<<x.asum()<<endl;
The results are unstable, sometimes it's right, some time it give error like,
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
or,
segment fault etc.
What's wrong there?