There are a couple of issues with your code. Also not necessarily but potentially leading to segfault but you should fix them while investigating your issue.
- dcopy signature is:
void cblas_dcopy (const MKL_INT N, const double *X, const MKL_INT incX, double *Y, const MKL_INT incY);
Two more comments about style:
- I would recommend to use same type for input and output variables of factorial e.g. unsigned long or unsigned double but not a mixed signature for a recursive function.
- As a user of this function, I would expect that I am responsible for allocating memory for m_exp. So I would but this into the function signature. Compare your function call to mkl's, all memory the user should take care of has to be taken care of by him, and all internal memory allocations are done internally without exposing it to the user, but in your case internal memory allocation for m_exp is exposed to the user. This potentially leads to a memory leak in the user code.