Serving the Quantitative Finance Community

 
User avatar
tigerbill
Topic Author
Posts: 1
Joined: April 22nd, 2004, 7:14 pm

Matlab to C++

April 6th, 2007, 6:13 am

I am looking for an efficient way to connect matlab file with C++ compiler. my M code runs only 20 seconds in Matlab while it takes 4 minutes after compiling to C++ and runs at visual C++ environment. anyone gives me a hint? thanks a lot.the command I use is:mcc -B sgl -W lib:BondMatlab1 -A debugline: on -O none -T link:lib MethodList1.mmcc -B sgl -W lib:BondMatlab2 -A debugline: off -O all -T link:lib MethodList2.mmcc -B sgl -W lib:xQStat_Mat -A debugline: on -O none -T link:lib MethodList3.mmcc -B sgl -W lib:xQuantMat -A debugline: on -O none -T link:lib MethodList4.m
Last edited by tigerbill on April 5th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
Sonyah
Posts: 0
Joined: December 11th, 2006, 3:58 pm

Matlab to C++

April 6th, 2007, 12:24 pm

 
User avatar
saliq
Posts: 0
Joined: April 10th, 2005, 1:55 am

Matlab to C++

April 6th, 2007, 7:48 pm

I found the following ppt presentation very useful for starting C++/Matlab integration...http://www.soe.ucsc.edu/classes/cmps060 ... %20C++.ppt
 
User avatar
Cuchulainn
Posts: 22929
Joined: July 16th, 2004, 7:38 am

Matlab to C++

April 9th, 2007, 3:31 pm

QuoteI am looking for an efficient way to connect matlab file with C++ compiler. my M code runs only 20 seconds in Matlab while it takes 4 minutes after compiling to C++ and runs at visual C++ environment.You must be doing something that the system was not built for. A C++ program can never be slower than the equivalent Matlab program ...
Last edited by Cuchulainn on April 8th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
tigerbill
Topic Author
Posts: 1
Joined: April 22nd, 2004, 7:14 pm

Matlab to C++

April 10th, 2007, 12:41 am

Thanks all. especially this link: http://www.codeproject.com/samples/mexFunction.asp helps me a lot."You must be doing something that the system was not built for. A C++ program can never be slower than the equivalent Matlab program ... "really? Cuchulainn, you are an expert on this, could you please elaborate a little more? thanks.
 
User avatar
ZmeiGorynych
Posts: 6
Joined: July 10th, 2005, 11:46 am

Matlab to C++

April 10th, 2007, 6:04 am

QuoteOriginally posted by: CuchulainnYou must be doing something that the system was not built for. A C++ program can never be slower than the equivalent Matlab program ...Ah, but what the Matlab compiler produces from matlab code is most likely not pure c++, but some (probably) Java glued together with matlab runtime binaries using (probably) JNI and with God knows what else... The fact that you can link it against C++ code doesn't mean all that much you knowUsing Matlab compiler never actually caused things to become _slower_ in my experience though. I'm curious as to what you're seeing. Is it perhaps because you're running it in VS.NET in debug mode? And besides, a 1000x1000 matrix inversion can very well be faster in Matlab (being passed directly to native BLAS routines) than a hand-rolled C++ version
Last edited by ZmeiGorynych on April 9th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22929
Joined: July 16th, 2004, 7:38 am

Matlab to C++

April 10th, 2007, 9:43 am

tigerbill,I think Zemi has given an answer better than I can do. He has real-world experience with Matlab.But indeed the generated code is something to look at; I would investigate the complete 'pipeline' from Matlab code to dll. But fom a C++ viewpoint, the translated code should run faster unless something went wrong in translation. Is it possible to see the translated code in a readable form? Can you describe the algorithm in general maths terms? QuoteAnd besides, a 1000x1000 matrix inversion can very well be faster in Matlab (being passed directly to native BLAS routines) than a hand-rolled C++ versionYou mean, really inverting a matrix or solving a linear system Ax = b? In many cases A has a special structure and rolled solutions are not too bad.
Last edited by Cuchulainn on April 9th, 2007, 10:00 pm, edited 1 time in total.