I have to pass arrays to other functions, through referencing or pointer, I don't care as long as it works fast. That's why I started to use the boost library. I did it in the following way:
using namespace boost;
typedef multi_array<long double, 4> array_type;
typedef multi_array<long double, 2> twod_array_type;
typedef multi_array<long double, 1> vec_type;
as functions:
void pde_3d_7_stencil_discretization(array_type& A, vec_type& b, vec_type& x,const int& xdim, const int& ydim,const int& zdim)
void gmressolver3d(array_type& A, vec_type& x, vec_type& rhs,const int& KrylovDim,const int& xdim,const int& ydim,const int& zdim,const int& COP, const int& threeDStencil)
and in the main function:
array_type A(extents[threeDimStencil][COP][COP][xdim*ydim*zdim]);
vec_type b(extents[xdim*ydim*zdim*COP]);
vec_type x(extents[xdim*ydim*zdim*COP]);
pde_3d_7_stencil_discretization(A,b,x,xdim,ydim,zdim);
gmressolver3d(A,x,b,KrylovDim,xdim,ydim,zdim,COP,threeDimStencil);
Obviously, I'm doing something wrong, because the code works really slower than the static version, which doesn't involve any references/pointers, just passing arrays from one function to another.
What can I do to accelerate this?
Thank you for any kind of help..
edit: I'm posting what these codes do, a sequence from GMRES solver: All arrays in it were initialized also using Boost, such as:
vec_type pp(extents[zdim*xdim*ydim*COP]);
vec_type ppp(extents[zdim*xdim*ydim*COP]);
vec_type w(extents[zdim*xdim*ydim*COP]);
vec_type y(extents[KrylovDim]);
vec_type vv(extents[zdim*xdim*ydim*COP]);
vec_type b(extents[KrylovDim+1]);
vec_type ro(extents[zdim*xdim*ydim*COP]);
vec_type out1(extents[xdim*zdim*ydim*COP]);
vec_type m_jac(extents[xdim*zdim*ydim*COP]);
twod_array_type h(extents[KrylovDim+1][KrylovDim]);
twod_array_type v(extents[zdim*xdim*ydim*COP][KrylovDim]);
twod_array_type hess(extents[KrylovDim+1][KrylovDim]);
array_type maa(extents[threeDStencil][COP][COP][zdim*xdim*ydim]);
array_type maaa(extents[threeDStencil][COP][COP][zdim*xdim*ydim]);
for (i=0;i<m+1;i++){
b[i] = 0;
for(k=0;k<m;k++){
h[i][k] = 0.0;
}
}
for (i=0;i<n;i++){
v[i][0] = ro[i]/r;
}
for(j=0;j<m;j++){
b[0] = r;
vector_zero_fill(n,ppp);
for(i=0;i<n;i++){
vv[i]=v[i][j];
}
//********************MATRIX FREE********************
matrix_vector_product_heptadiagonal_discret(A,vv,pp,xdim,ydim,zdim);
//two_vector_dot_product(n,pp,m_jac);
// if(isPrec)
// forback(A,pp);
//********************MATRIX FREE********************
//pretty fast**
for(i=0;i<=j;i++){
for(k=0;k<n;k++){
h[i][j] = h[i][j] + pp[k]*v[k][i];
}
}
for(i=0;i<=j;i++){
for(k=0;k<n;k++){
ppp[k] = ppp[k] + h[i][j]*v[k][i];
}
}
p=0.0;
for(i=0;i<n;i++){
w[i] = pp[i] - ppp[i];
p = p + pow(w[i],2);
}
h[j+1][j] = sqrt(p);
for(i=0;i<=j+1;i++){
for(k=0;k<=j;k++){
hess[i][k] = h[i][k];
}
}
for(i=0;i<j+1;i++){
c = hess[i][i]/sqrt(pow(hess[i][i],2)+pow(hess[i+1][i],2));
s = hess[i+1][i]/sqrt(pow(hess[i][i],2)+pow(hess[i+1][i],2));
for (k=0;k<=j;k++){
inner1=c*hess[i][k]+s*hess[i+1][k];
inner2=(-s)*hess[i][k]+c*hess[i+1][k];
hess[i][k] = inner1;
hess[i+1][k] = inner2;
}
b[i+1] = -s*b[i];
b[i] = c*b[i];
}