How can I deal with the large dimension array effectively ?
Show older comments
I have faced the problem of lack of memory. I want to compute the high dimension array which is up to rank 8(8-dimension). Basically, I made the matrix by using 'for' loops.
for in = 1:FF
for im = 1:FF
for ii1 = 1:WW
for i3 = 1:XX
for i4 = 1:KK
for i1 = 1:NN
for il = 1:FF
for ip = 1:FF
for iq = 1:FF
FGL1_nmvlpq(ii1,i3,i4,in,im,i1,il,ip,iq) = ...
FGR_nm(ii1,i3,i4,in,ip)*Fphi(i1,ip-il,i3,i4)*2*1i*eta* ...
1/(exp((omega(ii1)+DC*ky(i4)+FF(il)*Omega-mu)/T)+1)* ...
conj(Fphi(i1,il-iq,i3,i4))*conj(FGR_nm(ii1,i3,i4,iq,im));
The length of each vector is near 30. Is there a way to reduce the memory when calculate it? Please, help me...
p.s. the array is related to the mathematical function. However, there are a lot of variables; e.g. frequency, energy, Fourier indices, x and y position, dummy variables so that I need a high dimension array...
1 Comment
Rik
on 2 May 2017
Edited: per isakson
on 2 May 2017
I don't know an way to reduce the number of for-loops in a simple way. You should have a look at if you can convert some of these calculations to an element-wise operation, which can dramatically reduce the number of loops.
The method you are describing (many for-loops) is not the cause of your memory lack. That is intrinsic with such a big matrix. You should at least pre-allocate that last matrix ( FGL1_nmvlpq=zeros(WW,XX,KK,FF,FF,NN,FF,FF,FF)). You can try reducing the size of this matrix by using another datatype (using single or int16, instead of zeros), although this may not be an option for you.
If you really are having a memory issue, you could think about a method to split the results in a way that you will process them later on, as you probably will not be analyzing this thing as an 8D-array.
Answers (2)
Jan
on 2 May 2017
2 votes
If you create an 8 dimensional array with lengths of about 30, you need 5248.8 GB RAM, when you use doubles. I have the feeling, that using singles will not help also, because you will not have 2.6 TB of RAM also.
Why do you think, that storing such a huge array is useful? I bet, that you will not need all values and creating only the required values on the fly could be a much better idea.
Actually, FGL1_nmvlpq(ii1,i3,i4,in,im,i1,il,ip,iq) is 9 -dimensional, not 8. Let's see,
>> 9^30/1024/1024/1024/1024*8
ans =
3.0844e+17
>>
terabytes for a double. A single would cut it by 2 but that seems rather a puny savings in comparison... :)
Ain't agonna happen to get that much memory in a machine one suspects.
You'll have to limit the size of the universe you try to compute at any one time or be able to process the individual elements of the array individually to do whatever it is you want to do with each value.
Of course, the time required to even process the loop will be
>> ans/10E9/86400
ans =
3.9251e+14
>>
YEARS if could process each element in a nanosecond which is about a factor 100X faster than probably even theoretically possible.
Time (so to speak :) ) to rethink here...
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!