フィルターのクリア

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 Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by