Filter löschen
Filter löschen

Problems using parfor due to way variable is used

2 Ansichten (letzte 30 Tage)
Anders Jensen
Anders Jensen am 9 Dez. 2019
Bearbeitet: Adam am 9 Dez. 2019
Hello guys!
I have problems using parfor in this loop. It says: "The PARFOR loop cannot run due to the way variable 'minSSD', 'minCRSSSDCentrumCoordinates', 'minCRSSSDPatchMasks' and 'bestCoMasksCRS' are used.
function [minSSD, minCRSSSDCentrumCoordinates,minCRSSSDPatchMasks,bestCoMasksCRS] = OPM(featuresLibrary,patchSize,searchwindowSize,x,y,z,k,j,subjectPatchMask,zeroPatchMask,objectPatchMask,unitTest)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% Creates the mask of the subject patch
bestCoMasksCRS = cell(1,k);
minSSD= zeros(1,k);
minCRSSSDCentrumCoordinates = cell(1,k);
minCRSSSDPatchMasks = cell(1,k);
parfor i = 1:k
[centerPatchMask,topPatchMaskNN,topPatchMaskCenter,...
bottomPatchMaskNN,bottomPatchMaskCenter,rightPatchMaskNN,...
rightPatchMaskCenter,leftPatchMaskNN,leftPatchMaskCenter,...
frontPatchMaskNN,frontPatchMaskCenter,backPatchMaskNN,...
backPatchMaskCenter] = MaskInInitializationWindow(featuresLibrary{3,j},patchSize,searchwindowSize,zeroPatchMask,objectPatchMask,x,y,z,unitTest);
[templates, coMasks]=RandomTemplates(featuresLibrary{1,j},featuresLibrary{2,j}, unitTest);
[patchSubject,patchOutput] = PatchesFromMasks(featuresLibrary{3,j},...
templates,coMasks,subjectPatchMask,centerPatchMask,topPatchMaskNN,...
topPatchMaskCenter,bottomPatchMaskNN,bottomPatchMaskCenter,...
rightPatchMaskNN,rightPatchMaskCenter,leftPatchMaskNN,...
leftPatchMaskCenter,frontPatchMaskNN,frontPatchMaskCenter,...
backPatchMaskNN,backPatchMaskCenter, unitTest) ;
[bestPatchMatchTemp,bestCoMasks] = SSDOnPatches(patchSubject,patchOutput, k, unitTest);
[crsPatchMasks,crsPatches,crsPatchMaskCoordinates] = ConstrainRandomSearch(patchSize,searchwindowSize,bestPatchMatchTemp,x,y,z,k,unitTest);
[minSSD(1,i), minCRSSSDCentrumCoordinates{1,i},minCRSSSDPatchMasks{1,i},bestCoMasksCRS{1,i}] = SSDOnCRSPatches(...
bestCoMasksCRS,bestCoMasks,minSSD,minCRSSSDCentrumCoordinates,...
minCRSSSDPatchMasks,crsPatchMasks,patchSubject,crsPatches,crsPatchMaskCoordinates,k,unitTest);
end
end
Do you have a solution for this problem? Cheers!
Anders
  1 Kommentar
Adam
Adam am 9 Dez. 2019
Bearbeitet: Adam am 9 Dez. 2019
I've no idea what the code is doing - there's an alarming number of arguments being passed around in there, but this function call in particular raises eyebrows for a parfor loop (or even a regular for loop):
[minSSD(1,i), minCRSSSDCentrumCoordinates{1,i},minCRSSSDPatchMasks{1,i},bestCoMasksCRS{1,i}] = SSDOnCRSPatches(...
bestCoMasksCRS,bestCoMasks,minSSD,minCRSSSDCentrumCoordinates,...
minCRSSSDPatchMasks,crsPatchMasks,patchSubject,crsPatches,crsPatchMaskCoordinates,k,unitTest);
You are passing your entire arrays for minSSD etc into this function to calculate something, and are then writing an answer to just a single value in those same arrays.
This is confusing in numerous ways, but purely from the perspective of a parallel loop you cannot have calculation based on an array that each thread is writing to. What kind of answer are you expecting given that parallel processing does not maintain order of i from 1 to k like a for loop would (even in a for loop this code looks suspicious)? So each call to that function passing in minSSD is going to have different parts of it written at different times, and in an unpredictable manner, if it were allowed at all, which it isn't.
Hard to know what to advise as I really have no idea what the code is trying to do, but functions taking that many input and output arguments already raise plenty of questions.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

ME
ME am 9 Dez. 2019

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by