Thursday 1 May 2008

Matlab on amdx86_64 linux

About two weeks ago, I bumped into the problem with Matlab, refusing to compile mex file under linux AMD64. My desktop machine is opteron and our nodes on cluster AMD as well, so I spend some time figuring out what went wrong.
It turned out that in order to compile this small mex file (only three for-loops through sparse matrix) I had to pass -largeArrayDims option to mex.
But it caused a problem - instant crash on call to the mex function.
According to matlab help here you have to change all you int either to mwSize or to mwIndex. Since both of them will be translated into size_t it wasn't clear for me which one use and where. I followed tutorial, compiled and run my small mex file (created from fulltosparse.c example long time ago), but my calculation returned only sparse matrix full of zeros.
Matlab solution suggest to debug until you will a problem. I can't imagine a ways to debug 4000 X 4000 matrix multiplication and the problem clearly lies within use of mwIndex or mwSize. Also it is worth mentioning that I managed to repeat the fault on my powerbook just compiling with -largeArrayDims.
After spending whole day, trying to fix it, I found a proper solution, posted in comp.soft-sys.matlab. Unfortunately I cannot find this post now, but it is brilliant. I think it should be in matlab help, instead of the current solution. The chap (Tim Davis from CXSparse? Sorry, I didn't find this post again to give you proper credit) wrote:
Use
#define Int mwSignedIndex
and then replace all int with Int. Hurrah. It is now working and producing meaningful results.

No comments: