MATLAB: how to get the specs of the host machine - matlab

I have a MATLAB program that I intend to run on different machines. Is there a way to get, from within MATLAB itself, the following info:
Name of machine
Specs of machine, especially processor and memory configuration
Number of cores deployed for MATLAB
I know the command computer but I require more than what it outputs. I'd like to write all the info above to a text file.

You are looking for the following:
1) To check the type of computer on which MATLAB is executing, use: computer .
2) The following displays information about your Windows:
winqueryreg('HKEY_LOCAL_MACHINE',...
'Software\Microsoft\Windows NT\CurrentVersion','ProductName')
or in general, to get information about the OS, use: feature('GetOS').
3) To check number of processors, use: getenv('NUMBER_OF_PROCESSORS').
4) To check CPU information, use: feature('GetCPU').
5) To get information about cores, use: feature('numCores') .
6) To check memory used by MATLAB, total physical memory and some other information, use: memory.
Note that:
Some of the above are undocumented and taken from Yair Altman's blog.
Finally, to write data in a text file, you can use: fprintf .

Related

Stop execution when RAM is filled (i.e. avoid writing to Disk)

I have this problem:
I run some large calculations before going to sleep (or work).
When I return sometimes RAM is already filled and the program starts writing to Disk, which is a problem since then computer becomes almost non responsive, also the button "Interrupt the current operation" doesn't stop mserver.exe from executing a task.
This is what I saw 10 mins after I pressed the button "Interrupt the current operation":
Not to mention that calculations are probably like 100 or even 1000 times slower when it starts using Disk instead of RAM (so it's pointless anyway).
Another problem is that I was unable to save some variables to file since in Maple I couldn't type anything while mserver.exe was executing a task and after I killed the process mserver.exe I was still unable to save those variables since Maple commands don't work when connection to kernel is lost.
So, my question: can I make it so that mserver.exe won't use Disk at all (I mean from Maple alone, not by disabling page file in Windows) and just stop execution automatically when RAM is full (just like Classic Maple does when it hits 2GB limit)?
Also it would be nice to be able to limit Maple from using processor too much, for example up to 75% or so, so that I could work on that computer without problems.
You might experiment with a few of the options available for specifying limits on the Maple (kernel, mserver) engine.
In particular,
--init-reserve-mem=memorysize
(or, possible, the -T option). See here for some more detail:
https://www.maplesoft.com/support/help/MapleSim/view.aspx?path=maple
On Linux/OSX you could pass that in a call to the maple script that launches Maple. On MS-Windows you could add that to the command string/Property in the launcher (icon).
You might try setting it to a fraction of your total RAM, eg. 50-75%, and see how it goes. Presumably you'll have some other processes running.
As far as restricting the CPU use goes, that's more of a OS issue. On Linux/OSX you could use the system's nice facility. I don't know what's avaliable on MS-Windows (built-in or 3rd party). You might be able to set the Priority of the running mserver process from the Task Manager. Or you might look at something like the START facility:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/start

Why mode switch b/w user and kernel is required in OS?

OS has 2 modes i.e user and kernel mode.What is the need of these two modes to protect PCB?
Here's a good read on the differences:
http://blog.codinghorror.com/understanding-user-and-kernel-mode/
Basically, you want to keep user mode code from doing anything that could harm the computer ("harm" being defined as overwriting memory other processes are using, sending malicious/dangerous input to hardware, etc). But at the same time, you need to have access to these functions of the computer (i.e, you want your program to be able to open / read / write to files, etc) By segregating these functions to another program that runs in kernel mode (the "kernel" of your OS), you can do this.

MATLAB: How is it possible to see how much memory was used on a .m file?

As the title says, how can we see the memory that was used on a .m file(including functions) on MATLAB? Is there some command or something?
I would like to use it as a metric in my algorithm.
Thank you
At the command line, execute
profile -memory on;
and start the Matlab profiler as normal to see memory usage. However, you may need to copy information manually
There may be some alternatives, such as mtic and mtoc, depending on your Matlab version, which may allow feeding the data directly to a non-GUI output.
You can also start the profiler from the Editor Menu (at the top task bar of MATLAB GUI).
When you start the profiler, the codes executes normarly but when it exits/ends then the MATLAB displays all sorts of information that you want.
Including (but not limited to):
execution time
calls made
memory (I think! :P )

How to calculate running time of an executable file?

Is there any way to calculate exact execution time of an executable file?
Concretely, I am looking for a method that can be used to time an executable file compiled using Matlab. I am not referring to tic, toc.
Since you are asking about the execution time of an executable, I am assuming you are working in a command line environment.
In Linux, Unix, Mac OS X, etc, you can use the command line program time to measure runtimes. Assuming your executable file is called exefile.x, you would enter
time ./exefile.x
The output you will get looks something like
real 0m0.419s
user 0m0.112s
sys 0m0.174s
In Windows, there are tools such as timeit that measure runtimes. See for example How to measure execution time of command in windows command line? for further information.
Hope this helps.
PS: for an explanation of real, user, and sys, please refer to What do 'real', 'user' and 'sys' mean in the output of time(1)?
You could always include
tic
at the beginning of the executable, and then
disp(toc)
at the end.
tic-toc measure the execution time inside matlab. If you want your executable to be able to provide this information, you could provide an input parameter to instruct your program to run all the program between a tic-toc pair.
tic;
%process
toc;
Alternatively, if you want to measure it from outside, then there are different options dependent on the operating system. For example in linux there is the command time

Mex or Compile (mcc) Matlab function that uses toolkits

Environment:
Matlab R2012a (I have access to others if necessary)
All Toolboxes/Compiler installed
Ubuntu 12.04 64bit and/or Windows 7 64bit
I am working with the source for a software package written in Matlab (unfortunately its proprietary so no code examples...sorry), and one function briefly uses the Control System Toolbox and the Signal Processing Toolbox.
I have no problem running the code on my personal computer because I have every toolbox installed, however I would like to compile (mex or mcc) JUST the function using those two toolboxes. The goal, of course, is to run the software on a machine without those toolboxes, while leaving the remaining code open to change.
According to matlab, they have no problem with you compiling code that uses almost any toolbox. Here is the list of toolboxes that support mcc compilation:
http://www.mathworks.com/products/compiler/supported/compiler_support.html
The problem arises in that mcc no longer allows compiling with the -x option to create a mex-ed version of the function, so I'm forced to create a C executable (maybe? hopefully not). This particular function takes large matrices as parameters (impractical to write as a command line argument) and returns a structure of cell arrays.
The only way around this (as I see it now) would be to write the arguments (large matrices) to the hard drive in a binary .mat file , have the compiled C binary read in the arguments, run the algorithm, and finally save the return values in another .mat for the parent thread to load back into memory.
This seems totally impractical. I would greatly appreciate alternative suggestions. Please let me know if anything here in unclear. Thanks in advance!
[Edit 1] The codegen package does not support tf.m. It seems like this should be possible (and used to be possible with the mex -x option), but I'm at a loss. Any suggestions would be greatly appreciated!
I think the reason -x is not supported anymore is the fact that Matlab now has a product called "coder", which converts .m files to .c files and can also create .mex files from "suitable" .m files using the option -args to specify the input arguments: http://www.mathworks.com/videos/generating-c-code-from-matlab-code-68964.html