Reduce memory requirement of some vectorized operations

5 views (last 30 days)
In the following code, i perform some vectorized operations which happen to be highly memory intensive because my actual value of 'num' is 250. This is close to my limit, with 64 GB RAM. However, i would like to use a higher value. The goal of the code is to obtain the variable here called 'Energy_ind', which is only about 10 GB for num=250.
The main problem is the line:
Esiteindices = eindices(:,wbrdindic(:));
How can I do this same operation without the huge memory burden?
num = 100;
elnum = num^3;
brd = 4;
P = randi(4,[num num num]);
P_wbrd = padarray(P,[brd brd brd], 'circular');
elnum_wbrd = (num+brd*2)^3;
eoffsets = int32(randperm(171)');
%%%%%
allind = reshape(uint32(1:elnum),size(P));
allind_wbrd = padarray(allind,[brd brd brd],'circular');
eindices = repmat(eoffsets,1,elnum_wbrd);
for i=1:elnum_wbrd
eindices(:,i) = eindices(:,i)+i;
end
% get indices of O inside O_wbrd
wbrdindic_i = reshape(uint32(1:elnum_wbrd),size(P_wbrd));
wbrdindic = wbrdindic_i(1+brd:end-brd,1+brd:end-brd,1+brd:end-brd);
% Energy indices for elements in Owbrd(O)
Esiteindices = eindices(:,wbrdindic(:)); % BIG
clear eindices wbrdindic_i wbrdindic
Energy_ind = vec2mat(uint32(allind_wbrd(Esiteindices(:))),numel(eoffsets))';
clear Esiteindices
I am hoping this script can run without requiring significantly more memory than the total memory of 'Energy_ind'.

Answers (0)

Categories

Find more on Performance and Memory 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!