Linux frozen by assigning complex value to preallocated matrix

Hello, I have a question about matrix pre-allocation of complex data. When I run the following script on my CentOS5 x86_64 PC with 64G of RAM, no swap, it becomes unresponsive after using up all its memory. All I can do is to hard power-off or wait until OOM killer is invoked. The data are lost either way. This may be due to the virtual memory handling by Linux, but I wonder why Matlab couldn't detect it. When I asked the Mathworks customer service, they said it was a normal feature and intended behavior. Does anybody know how to efficiently avoid data loss? Simple error trapping by out of memory is enough for me....
----------------------------------------------
%HangTest.m
A = zeros(1024,1204,1024,5);
whos
A(end,end,end,end) = 1i;
whos
for n = 1:size(A,4)
A(:,:,:,n) = 1;
end
----------------------------------------------
>> HangTest
Name Size Bytes Class Attributes
A 4-D 50499420160 double
Name Size Bytes Class Attributes
A 4-D 100998840320 double complex
and unresponsive after this.
Thanks,
Masao

 採用された回答

Walter Roberson
Walter Roberson 2011 年 8 月 2 日

1 投票

You could try to do the initial allocation with
A(1024,1024,1024,5) = 1i;

5 件のコメント

Masao
Masao 2011 年 8 月 2 日
I tried:
A(end,end,end,end) = 1i;
as above but it didn't work. As the matrix get crowded, Matlab starts to go sluggish.
By the way, on my 32bit Windows platform this never happened.
Masao
Jan
Jan 2011 年 8 月 2 日
@Masao: I cannot believe, that you have been able to create a complex [1024 x 1024 x 1024 x 5] under 32 bit Windows, because it occupies 85.9 GB, but under 32 bit Windows only 3 GB can be addressed. And if you exhaust the memory under Windows, an unresponsive computer is the result exactly as under Linux.
Masao
Masao 2011 年 8 月 2 日
Sorry for the confusion. On 32bit windows I tried smaller matrix. When I tried to double its size by assigning one complex value Matlab responded with out of memory error. This is OK because I do not lose any data and just have to divide the problem and try again. Thank you for the comment.
Walter Roberson
Walter Roberson 2011 年 8 月 2 日
On 32 bit windows, the entire virtual memory for your process cannot exceed 4 GB, which is well within the amount of memory available for your system. 86 GB, though, exceeds your available RAM so it starts swapping to disk.
As you are on Linux, you could use a "ulimit" command before starting up MATLAB, if you want to restrict the amount of memory the process is permitted to use.
Masao
Masao 2011 年 8 月 3 日
Thanks Walter for telling me the command. It worked. ulimit -v (desired mem in kbytes) and Matlab gave me the error instantly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by