About running matlab in linux.

Hello, I run the same program in Windows it shows Out of memory. Type HELP MEMORY for your options. Then I run it in Linux, it runs for a while and then shows killed.
does it mean it is out of memory or something else? How to resolve it? Thanks.

 Accepted Answer

tlawren
tlawren on 26 Jun 2012
If you run some code on Windows and get an "Out of memory" error and then run the same code on Linux (on the same hardware) and Matlab just crashes, then yes, it might mean that you are out of memory in Linux too. Can you provide more details? What does your code do?
If you are in fact running out of memory, then the most obvious solution is to get more memory (if you can). Beyond that, you will have to re-write your code to work under your memory constraints. For instance, if you have big data matrices just sitting around doing nothing, then clear them away to make room for things you will use. If you make use of a lot of intermediate variables, try overwriting only a few variables instead.

8 Comments

Hi, actually not same system, windows is on my desktop, while Linux is the department's server which has more memory than my desktop.
I am constructing a matrix with size (3^5,3^5,10,1000) so it is (9^5)*(10^4)~10^9 space for that matrix.
I am thinking using int instead of double for each entry, do you know how to define a integer matrix? Thanks.
You can convert your data matrix to an integer type using int*(M). Where * is either 8, 16, 32, or 64 and M is your matrix. I don't know if that will help you though, because you need M loaded to convert it. Single precision types might be an option too. Also, check out the following link. http://www.mathworks.com/help/matlab/matlab_prog/strategies-for-efficient-use-of-memory.html
If you pre-allocate the array using zeros() or ones() you can specify the data class.
If you do not preallocate the array, then the data class of the first assignment to the array determines the data class used for the rest of the array.
Hi, Walter, yes I use ones() to pre-allocate the array, so every entry will be integer? How about zeros() and what is the difference?
For example, ones(6,3) allocates double precision filled with 1, but ones(6,3,'uint8') would allocate uint8 filled with 1. Likewise for zeros() except the initial value would be 0.
Oh, yes I tried it. Conventionally it allocates data for double precision, and if you convert it then it will change the precision. And I think it is better for me to convert it to int to reduce memory space. Let me try uint16 or 32 then. Thank you!
When you use the class type parameter to zeros() or ones() it never allocates the array as double precision, so it is better especially when you use large arrays.
Thank you!

Sign in to comment.

More Answers (1)

C Zeng
C Zeng on 26 Jun 2012
Also I find the answer to convert a matrix to single precision, that is 'single'. But I tried this command, but it still gives a double precision.
For example, a=ones(2,3,'single'); 1.5*a shows a double matrix. Could anyone explain it? Thanks.

7 Comments

Oh, sorry should be int*, but I cannot distinguish single and double precision, what is the difference?
'single' is a 32 bit floating point number; it has lower range and lower precision than double precision.
class() of the variable will show the precision.
For me, class(1.5*ones(2,3,'single')) shows single. The result might have been different in earlier versions.
You need to be careful when you combine expressions with mixed data types: sometimes MATLAB will adjust expand the expression to double precision and sometimes MATLAB will narrow down to integer. For example [pi 8.3 uint8(11)] will be uint8
What is an array contain more than one precision? Some of them are uint8 some of them are single? Shall I claim them separately after definition? Once claimed, will they change by some computation?
For example, a=ones(2,2) I want to first row is uint(8) second row is single. And will a(1,1) keep to be integer even though the computation gives the result of a double number?
It is not possible for a numeric array to have different datatypes (and so different precisions.) You would need to use a cell array for that.
Oh, so you mean ones() or zeros() is numeric array and they cannot have different data types, only defining cell(dim1,dim2..) can have different types for each dimension, right?
For example a=cell(2,4,3), and I want first matrix(:,:,1) is uint8, second is single, third is double. after definition, I need to convert as: uint8 a(:,:,1); single a(:,:,2);double a(:,:,3)
And will they keep this precision till the end of program? Is there a better way? Thank you!
Seems not so, it shows Conversion to uint8 from cell is not possible.
cell arrays have potentially data types per entry, not per dimension.
num2cell() converts numeric arrays into cell arrays.

Sign in to comment.

Categories

Tags

Asked:

on 26 Jun 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!