I am struggling with MATLAB installation. At the last step, it shows the following message:
However, I have the .net and gcc compilers on my system. It is odd that it also requires MATLAB compiler. Because it should be installed with the software itself automatically. I have never faced such problems when installing earlier versions of MATLAB.
You don't face a problem at all. The installation runs smoothly and MATLAB will work perfectly. Only if you want to translate MATLAB code to C code with the Matlab Coder toolbox, you require a C compiler (such as gcc or MinGW). This is obvious. Why should MATLAB ship a C compiler if there are plenty of open-source compilers (of which you maybe have a preference?) and there is no need for MATLAB (the main product) to run it?
With Simulink it is a bit less obvious but the argument is the same (why should MATLAB ship a C compiler?). Simulink is a model-simulation tool, calling a once-defined model over and over again at fixed (or dynamic) time steps. To speed up the calculation, it actually compiles the code first (note that MATLAB mainly uses a just-in-time-compiler). Those are .mex files, which is basically compiled C code (similar to a DLL). For this, it needs a C compiler and which brings us again back to the argument of why to ship one.
To make a long story short: Don't worry. Go ahead, this is not a problem and totally normal. As you said, you already have a C compiler installed (gcc), MATLAB will find it and you will probably not even note it if you start Simulink or the MATLAB Coder.
BTW, MATLAB always had required those compilers. Only the Java runtime is shipped with it since R2013-something because they had a major issue with the Java update back then and the tech support went nuts =P
Related
I have a Windows Matlab R2020a and was able to generate C source code for my Matlab function. However, I need to run a MEX file (for speed) on a Linux platform which has a Matlab installed (without Coder) and no way to install it (even trial version).
Please, provide the steps to compile this Matlab-generated C code on the linux (Ubuntu) system. I guess it can be done with gcc. I am unable to find a clear description on the web, as this process seems extremely complicated due to the obscure command line args needed to give to gcc (and i only rarely compile C code).
Please, note that generating C code using the MATLAB Coder App is not enough if you need a MEX file. MEX files have to contain a mexFunction function, which is not generated by the Coder App.
As a first step, I'd make sure your compiler is supported by MATLAB for the creation of MEX files. You can find the supported compilers on Linux here. Then I'd check whether the compiler is setup for Matlab to use it, as shown here. Finally, I'd have a look at some examples provided by Mathworks themselves: here
Once the C code (with the mexFunction) is ready, you can compile it using the mex command and use it on the Linux platform with no or minimal adjustments, depending on how heavily you rely on the functions defined in mex.h (which is the header your C file will have to import if you want to generate a MEX file).
You need the interface provided by the mexFunction for Matlab to be able to exchange inputs and outputs with the compiled function. Note that you can create other standard C functions (possibly defined in other C files) and call them from within the mexFunction as you would normally do in C. Basically, you can create your own libraries in C and then use them in Matlab via dedicated mexFunctions.
mex.h also provides the API to "convert" C data structures into Matlab data structures (e.g. arrays, cell arrays etc., all via the mxArray type).
There's a bit of a learning curve, mostly spent in understanding how to convert data back and forth between standard C and Matlab, but it's certainly worth your while. With a bit of care (e.g. switching to mxArray types only when absolutely necessary), you can end up having libraries of functions that can be used in standard C programs as well as in Matlab applications
I have built an standalone Matlab application. I was expecting it to be faster than running the application from the Matlab environent but it is indeed a bit slower (1.3 seg per iteration vs 1.5 seg per iteration)
I am not counting the init time required by MCR but the execution of my code.
Is that the expected performance or should I be obtaining a performance improvement?
I haven't found any settings on the deployment tool that could help to reduce execution time.
Thanks in advance
Applications built with MATLAB Compiler should execute at pretty much exactly the same speed as within MATLAB.
MATLAB Compiler does not convert your MATLAB code into machine code in the same way as a C compiler does for C. What it does is to archive and encrypt your MATLAB code (note, it properly encrypts it, not just pcodes it as a comment suggests), create a thin executable wrapper and package them together, possibly also with MATLAB Compiler Runtime (MCR). MCR is very similar to MATLAB itself, without a graphical user interface, and is freely redistibutable.
When you run the executable, it dearchives and decrypts your MATLAB code and runs it against the MCR. It should run exactly the same, both in terms of results and speed.
Very old versions of MATLAB Compiler (pre-version 4.0) worked in a different way, converting a subset of the MATLAB language into C code, and compiling this. This provided a potentially significant speed-up, but only a subset of the language was supported and results, unless you were careful, could sometimes be different. Similar functionality is now available in the separate MATLAB Coder product.
There are a few small things you can do to improve performance: for example, within deploytool you can specify which toolboxes your application uses. deploytool uses a dependency checker to package up all MATLAB functionality that it thinks your code might possibly depend on, but it can't always tell exactly, as the functions your code needs might change at runtime. It therefore errs on the side of caution and includes more than necessary. By specifying only the toolboxes you know to be necessary, you can speed things up a little (it also speeds up the build process quite a bit).
I have a project that requires lots of image processing and wanted to add GPU support to speed things up.
I was wondering if i compiled my matlab into c++ shared library and called it from within OpenCL program, does that mean that the matlab code is going to be run on GPU?
My own (semi-educated) guess is that you are going to find this very difficult to do. But, others have trodden the same path. This paper might be a good place to start your research. And Googling turned up Accelereyes and a couple of references to items on the Mathworks File Exchange which you might want to follow up.
Everything in jacket is written in c/ c++ / cuda.
Infact we now have a beta version libjacket (http://www.accelereyes.com/downloadLibjacket) which can be used to extend not just matlab but other languages if you are willing.
#OSaad
Most of our functions are the fastest options out there. Be it in C or matlab.
The Parallel Computing Toolbox in the upcoming release R2010b (due September 1st) supports GPU processing for several functions. Unfortunately, it only supports CUDA (version 1.3 and later), so with an ATI graphics card, you're out of luck. However, you may just want to buy a dedicated GPU, anyway.
Typically, if you can write your Matlab code in a "vectorized" way, then the packages like AccelerEyes and Jacket have a reasonable chance of making things run on the GPU. You can verify this to some extent beforehand by checking whether Matlab itself is able to run on multiple cores on the CPU (these days Matlab will use multiple cores if things are parallelizable in an obvious way).
If that doesn't work, then you need to drop down to C/C++ via mex and then, from there, call OpenCL yourself. Mex is how Matlab talks to C code, so you write C code that is called by Matlab (and receives the matrices, etc), then initialises and calls OpenCL. This is more work, but may be your only route (and, even if the automated packages work to some extent, this approach can still give more speedups because you can be smarter about memory management, for example, if you know what your are doing).
I'm now learning a bit of MATLAB and I have two versions of it. Version 4.2c, that I use on my emulated Windows 3.11 and the lastest one, that I use on my Windows Vista.
Here is a screenshot of it:
MATLAB 4.2c On My Windows 3.11 http://img9.imageshack.us/img9/4042/matlabv4.png
Then I want to know:
What are the main differences?
Are there are any differences in the language itself?
Will new libraries work?
EDIT: Now that I see the screenshot, I realize you really are referring to MATLAB Version 4.2c (R7). I thought perhaps you were mistakenly referring to the MATLAB Compiler instead, since I didn't think anyone would still be using a version that's over 15 years old! The oldest version I've used was when I first started learning MATLAB in 1996 on Version 5.0 (R8)!
The basic matrix and vector operations probably haven't changed much since Version 4.2c, although there are some newer functions to manipulate matrix data in different ways, like ACCUMARRAY, BSXFUN, and ARRAYFUN to name a few. Virtually everything else has probably changed in some subtle or not-so-subtle way: the MATLAB Desktop and Editor, graphics and plotting tools, creating graphical user interfaces, etc.. You can also do object-oriented programming now using MATLAB classes.
Anyhow, for all MATLAB releases starting from the newest Version 7.9 (R2009b) and going all the way back to Version 7 (R14, 2004) you can find the release notes on The MathWorks website. These release notes highlight the new features and bug fixes added to each MATLAB version since the previous release. For example, in order to see the difference between Versions 7.6 and 7.9, you'd have to look through the release notes from 7.7, 7.8, and 7.9. If you really need release notes going farther back in time, you will probably have to contact the MathWorks directly.
P.S. I may actually still have my old notes from my first MATLAB course, which I'm tempted to dig out of storage and take a look at just to see what may have changed since then. ;)
what isn't different?
I have no idea how much new has been added since then. I remember first learning about MATLAB around then and turning my nose up at the program... my guess is that you would find all the basic operations the same, because I remember these things working:
vector & matrix manipulation
elementary functions
basic plotting (e.g. plot, subplot functions)
.m file syntax
There's all sorts of stuff nowadays, particularly the toolboxes, things like the integrated debugger (breakpoints!) and profiler, just-in-time compilation (for-loops are much quicker now), GUI development, object-oriented syntax, Simulink, etc. etc.
You'll just have to try it and see... I have found in the last 10 years that there has been very little backwards compatibility trouble with matlab. The only thing I can remember that was challenging was some of the corner cases changed with handle graphics between v6 and v7.
There are a huge number of differences since that time. New variable types (logical, sparse, cell arrays, uint(N), single, etc.), objects, anonymous and nested functions, gui tools, toolbox changes galore.
Having said that, I have code written in 1988 (20+ years) that still runs with essentially no change. (Maybe version 3.5 or so?) And I just tripped recently over a piece of code from that era that is still actively being used.
The MathWorks does make great efforts to continue backwards compatibility for all code. Only under a great deal of discussion do they break that rule.
I'm trying to run a program originally tested on Matlab 6.5 on a new release (R2009a)
The program uses some mex files, and I get the following error when trying to run it:
??? Invalid MEX-file '/normalizedCut/common_files/sparsifyc.mexglx':
normalizedCut/common_files/sparsifyc.mexglx: symbol mxGetIr, version
libmx.INTERNAL not defined in file libmx.so with link time reference.
(the code I'm trying to tun is Normalized cut by Shi & Malic, and can be found here:
http://www.cis.upenn.edu/~jshi/software/files/NcutClustering_7.zip)
If I try to run the code on the same system but Matlab 2007a it runs ok.
Is there some problem with backwards compatibility for 2009a?
Are there any flags somewhere in the system I can change to help it work?
When I googled it I saw some references to the LD_LIBRARY_PATH env variable, but what exactly should be added to it I could not find out.
Thanks,
Yair
The source code for those mex functions appears to be available in the "Image segmentation with normalized cuts" source on this page: http://www.cis.upenn.edu/~jshi/software/ (in the specific_NcutImage_files subdirectory in the unpacked .zip)
It's pretty common for there to be problems running mex functions with different versions of Matlab. The errors you're getting look like they're due to API changes in Matlab (though that surprises me a little). I've had the most trouble because of binary incompatibilities induced by changes in gcc. I'd suggest contacting Jiambo and asking him if he can build a new version or release the source.
Worst case, you could try re-implementing those mex functions. The normalized cut algorithm is pretty straightforward in Matlab (see the Shi and Malik paper). By the names of the mex functions, they look like they're mostly duplicating existing matlab functionality (matrix multiplication, matrix sparsification). There's a non-zero chance that if you re-implemented them as regular m-code functions they'd be faster anyway due to the multicore support that's been added to Matlab.