MATLAB: Linux frozen by assigning complex value to preallocated matrix

MATLABmemoryout of memorypreallocation

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

Best Answer

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