Parfor loop increase memory usage

2 Ansichten (letzte 30 Tage)
Diego Leal
Diego Leal am 5 Okt. 2018
Kommentiert: Edric Ellis am 8 Okt. 2018
Hello,
I am using parfor to process to read several thousand csv files in a directory, perform some operations on each file independently, and save the output. Each of the csv files is not bigger than a couple of MB and I am using about 15 workers. Yet, I seem to run out of all of my 64GB of RAM memory. I notice that the memory usage per worker gradually increases as the loop progresses, from 500MB to 900MB only after a few dozen files have been read.
The pseudocode looks like this:
file_names = dir( directory_with_files);
L = length(file_names);
parfor i = 1:L
%read file
data = readtable( file_name );
result = some_function( data );
f = figure('visible','off');
plot( result );
savefig( f );
close( f );
end
I am trying to be careful about assigning the read file to the same variable so that it overwrites it, closing all plot figures and so on. The only thing I can think of is that the function I use in the parfor is fmincon and it displays a message of whether the optimization was successful or not, and another function in the parfor also displays some messages. Could this be causing the increasing memory usage? What other things can I do to process these files in parallel? Again, the file sizes are very small and I should have several times enough memory for this task,
thank you,
PS: I am using 2018a
****** EDIT ***** I include below the full code:
list = dir('~/Documents/matlab_files/*.csv');
L = length(list);
parfor i = 1:L
data = readtable(strcat('~/Documents/matlab_files/',list(i).name));
all_para = [0.53,0.3,0.001,0.001];
try
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(all_para)func_min(all_para,data),...
all_para,[],[],[],[],...
[-5,-5,0.01,0.01],...
[5,5,5,5]);
M = func_eval(x, data);
csvwrite(strcat('~/Documents/output/',list{i},'outM.csv'),M);
f = figure('visible','off');
plot(M);
saveas(f,strcat('~/Documents/output/',list{i},'.png'));
close(f);
catch ME
fprintf('fmincon failed: %s\n', ME.message);
continue;
end
end
  5 Kommentare
Diego Leal
Diego Leal am 5 Okt. 2018
hello @OCDER,
thank you for your help,
I copy below the full actual code:
list = dir('~/Documents/matlab_files/*.csv');
L = length(list);
parfor i = 1:L
data = readtable(strcat('~/Documents/matlab_files/',list(i).name));
all_para = [0.53,0.3,0.001,0.001];
try
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(@(all_para)func_min(all_para,data),...
all_para,[],[],[],[],...
[-5,-5,0.01,0.01],...
[5,5,5,5]);
M = func_eval(x, data);
csvwrite(strcat('~/Documents/output/',list{i},'outM.csv'),M);
f = figure('visible','off');
plot(M);
saveas(f,strcat('~/Documents/output/',list{i},'.png'));
close(f);
catch ME
fprintf('fmincon failed: %s\n', ME.message);
continue;
end
end
where "func_min" is the function I am minimizing in fmincon, and func_eval is another separate function, but note that the input in both is just "data" and x or all_para, which are created inside the parfor.
Edric Ellis
Edric Ellis am 8 Okt. 2018
A few questions:
1. What release of MATLAB/PCT are you using
2. What OS are you using
3. Are you able to come up with a simplified but executable example that demonstrates the problem you're seeing
I tried to reproduce the problem using R2018a on Linux using 1000 simple numeric CSV files of about 3MB each, where I was calling readtable, plot, and saveas in a parfor loop. I didn't see any increase in memory usage on the workers.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by