Page 1 of 1
Matlab to C++
Posted: April 6th, 2007, 6:13 am
by tigerbill
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
Matlab to C++
Posted: April 6th, 2007, 12:24 pm
by Sonyah
Matlab to C++
Posted: April 6th, 2007, 7:48 pm
by saliq
I found the following ppt presentation very useful for starting C++/Matlab integration...
http://www.soe.ucsc.edu/classes/cmps060 ... %20C++.ppt
Matlab to C++
Posted: April 9th, 2007, 3:31 pm
by Cuchulainn
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 ...
Matlab to C++
Posted: April 10th, 2007, 12:41 am
by tigerbill
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.
Matlab to C++
Posted: April 10th, 2007, 6:04 am
by ZmeiGorynych
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
Matlab to C++
Posted: April 10th, 2007, 9:43 am
by Cuchulainn
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.