필터 지우기
필터 지우기

How Can I Parallel this?

조회 수: 2 (최근 30일)
DB
DB 2023년 4월 28일
댓글: Walter Roberson 2023년 4월 28일
Hello,
Can the code below be done in parallel? RTBlock.mat file has the necessary variables for the ART function. ProductImage in block 2 uses the ProductImage from block 1, etc. Any ideas how I can parallel or speed up this code? It seems impossible, but I'm wondering if anyone out there has defied the odd.
%Initial setup
ProductImage = InitialRimage; % Setup the initial ProductImage
for block = 1:10
%Uncompress 336 X 25 cells
load(['c:/Project/RTBlock_' num2str(block) '.mat']);
ProductImage = ART(block, Pointers, Weights, ImageGain, ErrorGain, TrueScan, ProductImage);
end
I'm using MATLAB R2023a with Image Processing & Parallel Computing Toolboxes. I have access to 14 cores, 20 logical processors, and Nvidia RTX 3080 GPU.
Thanks in advance!

답변 (1개)

Walter Roberson
Walter Roberson 2023년 4월 28일
Running it in parallel is only possible if the calculation being done turns out to be a reduction variable; see https://www.mathworks.com/help/parallel-computing/reduction-variable.html
  댓글 수: 2
Raymond Norris
Raymond Norris 2023년 4월 28일
@DB do you have a collection RTBlock projects? Within your project folder you have 10 MAT-files that you're looping through. As Walter mentioned, unless ProductImage is a reduction variable (and by the sounds of it, I'd say no), another consideration is to loop over set of projects (in parallel). For instance
list_of_projects = dir('c:\Project*');
parfor idx = 1:numel(list_of_projects)
unit_of_work(idx)
end
function unit_of_work(idx)
%Initial setup
ProductImage = InitialRimage; % Setup the initial ProductImage
mat_files = dir('c:\Project\RTBlock_*.mat');
for block = 1:numel(mat_files)
%Uncompress 336 X 25 cells
load(['c:/Project' num2str(idx) '/RTBlock_' num2str(block) '.mat']);
ProductImage = ART(block, Pointers, Weights, ImageGain, ErrorGain, TrueScan, ProductImage);
end
Also keep in mind, running a local pool will (by default) cancel out any multi-threading. The gain of multi-processing might be partially canceled out by the lack of multi-threading.
Walter Roberson
Walter Roberson 2023년 4월 28일
Also;
In some cases, if the results of the previous block are not needed until "late" in the calculation of the new block, then you can overlap calculations by using SPMD and labSend() the completed until to the next unit in the chain. You would probably only want to be using a pool size of 2 for that, I think.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by