parfor error: The variable objectEdges in a parfor cannot be classified.
2 次查看(过去 30 天)
显示 更早的评论
brief aside: Isn't the sequential processing of loop iterations bye parfor the same as the for loop?
The goal is to process 100 images. A snipet of the processing code is included below. A supercomputer cluster is available for processing. What is the best way to approach the problem? Each output needs to be saved separately. How is this solved?
Also, help parpool parpool not found.
ERROR: Error: The variable objectEdges in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
CODE:
kBW = kirschImage > 0;
kBinaryFill = imfill(kBW,'holes');
kProps = regionprops(kBinaryFill,'PixelIdxList');
objectEdges(1:length(kProps)) = struct('pixelList',[]);
for j = 1:length(kProps)
object = kProps(j).PixelIdxList;
for w = 1:length(object)
[X,Y] = ind2sub([N,M],object(w));
if ( (X-N)~=0 & (Y-M)~=0 )
hoodSearch = [kBinaryFill(X-1,Y),kBinaryFill(X,Y),kBinaryFill(X+1,Y),...
kBinaryFill(X,Y-1),kBinaryFill(X,Y+1)];
hoodFind = length(find(hoodSearch));
if ( hoodFind~=5 )
linInd = sub2ind([N,M],X,Y);
objectEdges(j).pixelList = [objectEdges(j).pixelList; linInd];
end
end
end
end
kEdge = zeros(N,M);
for j = 1:length(objectEdges)
kEdge(objectEdges(j).pixelList) = 1;
end
2 个评论
Edric Ellis
2015-6-4
It's not clear where your parfor loop is here. Please could you post a minimal reproduction that shows the error that you're encountering.
What release of MATLAB/PCT do you have installed? Before R2013b, you need to use matlabpool rather than parpool.
Walter Roberson
2015-6-9
To answer the question "Isn't the sequential processing of loop iterations bye parfor the same as the for loop?":
No. The order that parfor uses to execute the iterations is unspecified and dynamic according to how long the iterations take.
In the case of a single worker, historically parfor will execute the loop in reverse order from sequential. Or perhaps it uses "maximum to minimum" (which might be the same order as normal if the loop increment was negative.) Or perhaps it analyzes the form of the indexing expressions and figures out whether the smallest or largest loop value will produce the largest index (since you might have CONSTANT-INDEX) and runs the loop in the order that processes the largest first. It isn't specified. For loops that count up and which do not subtract the index from something, the known order is reverse (largest first), which has the side effect of allocating the entire output array because it writes into the largest offset.
回答(2 个)
Cindy Solomon
2015-6-5
I second Edric to please provide the minimum reproduction steps and clarification what you are using parfor for. I have seen a similar error when trying to write field values of a structure in a "parfor" loop. As a workaround, you could create a temporary variable in a "parfor" loop and then assign it back to the field in a separate "for" loop. However, I am not sure if this is the case with your code- clarification would be very helpful.
Hope this helps!
0 个评论
Walter Roberson
2015-6-5
If the whole thing is inside a parfor that is not shown here, then your line
objectEdges(1:length(kProps)) = struct('pixelList',[]);
is a problem if objectEdges is an output variable instead of a local variable. Output variables must be indexed by an expression involving the parfor loop variable.
2 个评论
Walter Roberson
2015-6-9
Your first line in your "for" is
objectEdges = struct('pixelList',[]);
which writes into all of objectEdges.
Your last line of your "for j" is
objectEdges(j).pixelList = pixelList;
which writes into the j'th element of the objectEdges that was created for this iteration. The very next iteration of "j" that change is going to be lost, as all of objectEdges is going to be overwritten.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!