How can I save matrices in par-for-loop?
Ältere Kommentare anzeigen
Hi all,
I'm using MATLAB's par-for-loop to process some experimental data, which is large in size. The result of each iteration is a matrix, but the sizes of the matrices generated by different iterations are different. I'm using a cell to collect the data, and yet it turns out to be inefficient. What I've implemented now is as follows,
load('dataset.mat', 'data');
load('matsize.mat', 'matsize');
data = parallel.pool.Constant(data);
matsize = parallel.pool.Constant(matsize);
N = 24;
results = cell(N,1);
parfor L = 0:N-1
cursize = matsize.Value(L+1);
matrix(1:cursize, 1:cursize) = calculateSomething(data.Value, L);
% the matrix is very large, can be up to size of 2^N, whose sizes are differnt for each L
results{L+1} = matrix(1:cursize, 1:cursize);
end
save('results.mat', 'results');
% MATLAB version: 2019a
I use ticBytes and tocBytes to test the data passing process and find that massive data is transferred from workers to client. Is there any way to avoid this and allow data to be directly written in the same block of memory as pre-allocated, and thus improve the efficiency of the code?
Thanks a lot!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!