issue with Multithreading in MATLAB?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have very long for loops i.e.
for i=1:109771
% Many steps
% STEP FOR APPENDING A MATRIX INTO A gif
end
Each step in for loop takes about 3 seconds. Is there a way to do this in parallel processing?
Can you please help me with an example. On how to modify this above code to get it working in a High Performance Computing environment.
On how many cores can I run this code?
Sincere Regards,
Sanchit
댓글 수: 0
채택된 답변
Walter Roberson
2019년 8월 1일
pool_cluster = 'myCluster';
numframes = 109771;
frame_rows = 512; %adjust as appropriate
frame_cols = 768; %adjust as appropriate
frame_panes = 3; %1 for grayscale or pseudocolor
cmap = []; %256 x 3 for pseudocolor
gif_frame_rate = 22; %fps
gif_delay = 1/gif_frame_rate;
gif_array = zeros(frame_rows, frame_cols, frame_panes, numframes, 'uint8');
myCluster = parcluster(pool_cluster);
parfor (frameidx = 1 : numframes, myCluster)
%many steps
thisframe = something_appropriate; %that is frame_rows x frame_cols x frame_panes
gif_array(:, :, :, frameidx) = thisframe;
end
if frame_panes == 1 %only valid for grayscale or pseudocolor
imwrite(gif_array, cmap, 'YourGifFileName.gif', 'DelayTime', gif_delay);
else %rgb has to be appended a frame at a time
imwrite(gif_array(:,:,:,1), cmap, 'YourGifFileName.gif', 'DelayTime', gif_delay, 'WriteMode', 'overwrite');
for frameidx = 2 : numframes
imwrite(gif_array(:,:,:,frameidx), cmap, 'YourGifFileName.gif', 'DelayTime', gif_delay, 'WriteMode', 'append');
end
end
"On how many cores can I run this code?"
The above code is for the case where you have a Distributed Computing license and a cluster named myCluster has been configured. The number of cores that would be used would depend upon what was specified in the cluster profile. It is common for the number of cores configured in a profile is the number of physical cores on the cluster, but other numbers could be configured for economic or policy reasons.
댓글 수: 5
Walter Roberson
2019년 8월 2일
The writing of the file cannot be within the parfor, but you can save all of the imind, cm as you generate them.
Caution: getframe does not always return the same size output unless you pass it the size to capture. Axes frame sizes turn out to vary slightly depending on titles and tick text and axes labels
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Orange에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!