Parallelization of a Loop with 'parfor - Unsuccessfully

1 回表示 (過去 30 日間)
Royi Avital
Royi Avital 2014 年 9 月 13 日
コメント済み: Matt J 2014 年 9 月 13 日
Hello, I created an algorithm which work on Image Patches. I go through matrix of an image and apply a function of a neighborhood predefined.
For some reason MATLAB won't allow me using the 'parfor' command.
Here is the code:
mInputFrames = padarray(mInputFrames, [searchWinEffRadius searchWinEffRadius], 'replicate');
parfor iRowIdx = 1:videoFramesNumRows
for jColIdx = 1:videoFramesNumCols
paddedImageRowIdx = iRowIdx + searchWinEffRadius;
paddedImageColIdx = jColIdx + searchWinEffRadius;
vSearchWindowRowIdx = [(paddedImageRowIdx - searchWinEffRadius):(paddedImageRowIdx + searchWinEffRadius)];
vSearchWindowColIdx = [(paddedImageColIdx - searchWinEffRadius):(paddedImageColIdx + searchWinEffRadius)];
for kFrameIdx = 1:videoFramesNumFrames
vPatches = ((kFrameIdx - 1) * singleFrameSearchWindowNumPixels) + ...
[1:singleFrameSearchWindowNumPixels];
mCurrSearchWindow = mInputFrames(vSearchWindowRowIdx, vSearchWindowColIdx, kFrameIdx);
mCurrSearchWindowPatches(:, vPatches) = Im2ColSliding(mCurrSearchWindow, [localWinSize, localWinSize]);
end
mOutputFrame(iRowIdx, jColIdx) = PatchFilter(mCurrSearchWindowPatches, refPixelRowIdx, refPixelColIdx, vGaussianKernel, weightsStd);
end
end
The error I'm getting: "The PARFOR loop cannot run due to the way variable 'mCurrSearchWindowPatches' is used.
The work on the loops is per pixel which is completely indepndent (In the result) from its neighborhood. What can I do to allow the parallelization to kick in?
Thank You.

採用された回答

Matt J
Matt J 2014 年 9 月 13 日
編集済み: Matt J 2014 年 9 月 13 日
Pre-allocate mCurrSearchWindowPatches somewhere in the parfor loop but prior to the loop over kFrameIdx.
  2 件のコメント
Royi Avital
Royi Avital 2014 年 9 月 13 日
Hi Matt, It worked.
Could you explain the logic behind it?
What made you know about it?
Thank You.
Matt J
Matt J 2014 年 9 月 13 日
See the section "Uninitialized Temporaries" at this link,

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by