问题
When I use some code like,
x = randi(100,[1000 1000000]);
I get the Out of Memory
error.
However when I have,
x = randi(100,[1000 500000]);
I don't get any error but my laptop almost stops working!
and that sometimes costs me a force shutdown
.
I would really prefer the Out of Memory
error!
Q1+Q2: Is there a threshold for that error, which I could adjust?
Q3: Or any other suggestions (maybe limit the memory that MATLAB can have access)?
Thanks,
回答1:
A1: Yes, the Memory is the Treshold
While the Memory is a limit, your observation of "almost stops working" is related to the CPU-bound processing associated with a task to calculate value for all 500,000,000 elements and get 'em stored. As you can see in A3 this attempt takes 4GB RAM storage to handle just the x
.
A2: Yes. Add more Memory to adjust the Treshold
If your problem requires larger objects, get more space to store it, if your CPU-bound observation matters, go get the computation from distributed processing ( be it a Cloud or a Grid ) to off-load your localhost.
A3: Yes. Check MATLAB memory consumed using whos
mCloud:1> x = randi( 100, [1000 500000] );
mCloud:2> whos
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
ans 1x70 757 cell
x 1000x500000 4000000000 double
Total is 500000070 elements using 4000000757 bytes
mCloud:3>
来源:https://stackoverflow.com/questions/26691520/is-there-a-threshold-for-out-of-memory-error