S****8 发帖数: 401 | 1 遇到的问题是,手头有一堆matlab legacy code,其中一部分generate一个database,
另外一部分基于这个database做一些运算。 因为这部分运算很慢,所以想转移到c或者
fortran下面去,请教大牛这种情况最佳选择应该怎么弄?(因为某些原因,不可能全
部重写这些legacy code)谢啦! | k**********g 发帖数: 989 | 2
到c
(1) MEX C (C++ can also be used.)
http://www.mathworks.com/help/matlab/ref/mex.html
Drawbacks:
(1.1) Each MEX C library (DLL) can only export one MATLAB function.
(1.2) While that MEX C function is executing, MATLAB cannot perform any
other operations. MATLAB will remain blocked.
(1.3) When the MEX C function finishes, it is terminated. Any data that is
not returned back to the MATLAB workspace will be lost. It cannot retain any
"object state" in the memory.
Because of the limitations, MEX C (or C++) cannot be used to implement
object-oriented programming style module.
(2) MATLAB COM (Component Object Model) integration
Primarily intended for Windows. Probably not available on other OSes.
http://www.mathworks.com/help/matlab/matlab_external/introducin
Advantages:
(2.1) If your legacy code already have COM interface, you don't need to do
anything. Just follow the instructions and use it.
(2.2) Supports object-oriented programming style. COM objects can have
states across method calls from MATLAB.
Drawback:
(2.3) The development cost of COM interface is very high. If the legacy code
does not already have COM interface, this approach cannot be justified.
(3) MATLAB Java interface
Available on all platforms. In fact, part of the MATLAB's rich GUI is built
using its own Java interface.
http://www.mathworks.com/help/matlab/matlab_external/product-ov
Advantages
(3.1) Mature technology available on all OSes.
(3.2) Supports object-oriented programming style.
Drawbacks
(3.3) Each version of MATLAB is tied to a certain Java JRE version. To load
your own Java class files, these classes must also be build using the same
JDK version.
(3.4) Long-running processes with MATLAB-Java interface may have memory-
leakage issues, unable to unload classes (clear java sometimes does not work
reliably), etc.
see: MATLAB "clear java" command
http://www.mathworks.com/help/matlab/ref/clear.html#bt2ite1
The solution to issue (3.4) is to invest in good software architecture and
coding practices in the development of your Java modules.
(4) MATLAB DotNet (.NET) interface
(Currently only on Windows x86 and x86-64. Not available on Linux, Mono, or
WinRT.)
http://www.mathworks.com/help/matlab/getting-started.html
It is similar in nature to the MATLAB Java integration.
Advantages
(4.1) Easy to use. About as easy as the MATLAB Java interface.
Disadvantages
(4.2) Slightly less mature than the MATLAB Java interface.
Some less common language features found on C# or the CLR (Microsoft common
language runtime) specification may not be accessible from MATLAB.
(5) Command-line execution
MATLAB can execute commands on a command-line shell via the "system" command.
http://www.mathworks.com/help/matlab/ref/system.html
Consideration
(5.1) If the MATLAB code only makes very few such calls, command-line
execution can be considered because it is very easy to implement.
(6) Inter-process Communication
This requires good familiarity with writing programs to use the OS inter-
process communication API.
A "server" (also known as "worker") process will be launched outside MATLAB.
This server will listen on an IPC channel.
A "client" is developed using one of the aforementioned object-oriented
approach (MATLAB COM integration, Java class, DotNet (C#) class). From the
MATLAB environment, commands and data can be sent to the server (worker) for
execution in a process that is separate from the MATLAB.
----
Disclaimer: Yes, I've done all of the above. (Some more than 10 years ago.)
【在 S****8 的大作中提到】 : 遇到的问题是,手头有一堆matlab legacy code,其中一部分generate一个database, : 另外一部分基于这个database做一些运算。 因为这部分运算很慢,所以想转移到c或者 : fortran下面去,请教大牛这种情况最佳选择应该怎么弄?(因为某些原因,不可能全 : 部重写这些legacy code)谢啦!
|
|