Pre-calculating memory usage of repmat.m to avoid out of memory errors
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
A and B are equal length vectors of my data. The max value in A is 100 and the max value in B is 20,000 and n = 2,500. I wish to run the following code
n = length(A); % length(A) == length(B);
a = 1; b =1;
gridx1 = [1 : a : max(ceil(A))];
gridx2 = [1 : b : max(ceil(B))];
[gridx2,gridx1] = meshgrid(gridx2,gridx1);
x1 = repmat(gridx1, [1,1,n]);
x2 = repmat(gridx2, [1,1,n]);
mu1 = repmat(A,[length(gridx1),length(gridx2),1]);
mu2 = repmat(B,[length(gridx1),length(gridx2),1]);
However I get an out of memory error. Hence I need to reduce the sampling frequency of the grids.
Lets say I wish to allocate up to 3GB of RAM to this process, how can I find the sampling frequency, "a" and "b".
Obviously I wish to sample at the maximum frequency possible (subject to the 3GB constraint) to get the most accurate answer.
thank you
2 Kommentare
Jan
am 7 Feb. 2013
Isn't this a simple division? Do 3GB belong to one oy the arrays e.g. mu2, or is it the sum of all defined arrays?
Jason Ross
am 7 Feb. 2013
Bearbeitet: Jason Ross
am 7 Feb. 2013
I'll state what I hope is pretty obvious: If you are regularly hitting "Out of memory" issues, you really should move to a 64-bit operating system. The hardware and operating systems have supported it for years now. Barring a few specialized use cases (generally related to hardware drivers), there is no downside to moving to a 64-bit operating system. RAM is also quite inexpensive, 16 GB can be had for less than $100, 24 GB less than $150, 32 GB less than $200 and even 64 GB is running ~$350. This, of course, assumes a desktop host with a motherboard that can take these types of chips.
Akzeptierte Antwort
Weitere Antworten (1)
cr
am 7 Feb. 2013
Bearbeitet: cr
am 7 Feb. 2013
say, Lg1 is length(gridx1) and Lg2 is length(gridx2). Then your variables need this much memory x1: Lg1*Lg2*n*8 bytes (assuming you are using doubles), x2: Lg1*Lg2*n*8 bytes This is where the problem lies. Other not so big. Use singles or integer types if doubles are not necessary. Or, do your operations sequentially clearing intermediate variables.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!