Error using Parfor "Unable to classify the variable 'Sort'"
10 ビュー (過去 30 日間)
古いコメントを表示
Please help, pulling my hair out;
The following code is meant to sift through arrays Sort and Sort2 looking for intersections, and then if it finds one it reassigns that line (k) to all zeros. Sort is 16.777E6 x 24, and Sort2 is 24x24 matrix. k runs from 1 to Np = 16.777E6. This segment of the whole program takes considerable time with very, very large versions of Sort, so I am trying to use parfor to speed things up. I assumed this could be done because the results of any line Sort(k) do not affect any other line of Sort(k).
The error specifically says "Error using Solver_V (line 647)
Error: Unable to classify the variable 'Sort' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in
parfor-Loops".
The offending portion of code is below, and I included the full files for context.
Thank you so much!
parfor k=1:Np
for i=1:(Nu-1)
for j=(i+1):Nu
if Sort(k,i)*Sort(k,j)==1 && Sort2(i,j)==0
Sort(k,:)=zeros;
flag=1;
break
end
end
if flag==1
flag=0;
break
end
end
if mod(count2,10E6)==0
count2-count1
count2
end
count2=count2+1;
end
0 件のコメント
採用された回答
Raymond Norris
2021 年 7 月 23 日
Try this refactoring the for-loop a bit
parfor k=1:Np
flag = 0; %#ok<PFTUSW>
for i=1:(Nu-1)
for j=(i+1):Nu
% if Sort(k,i)*Sort(k,j)==1 && Sort2(i,j)==0
% Sort(k,:)=zeros;
% flag=1;
% break
% end
tmp_S = Sort(k,:);
if lFoundIntersection(tmp_S,i,j,Sort2)
Sort(k,:) = zeros;
flag = 1;
end
end
if flag==1
flag=0;
break
end
end
if mod(count2,10E6)==0
count2-count1
count2
end
count2=count2+1;
end
At the end of your script, add
function tf = lFoundIntersection(Sort,i,j,Sort2)
tf = Sort(:,i)*Sort(:,j)==1 && Sort2(i,j)==0;
end
I think you'll also need to comment out this
if mod(count2,10E6)==0
count2-count1
count2
end
3 件のコメント
Raymond Norris
2021 年 7 月 23 日
I would suggest two things:
- Make Solver_V a function and not a script. This will scope what variables are in the script's workspace.
- Change the parfor back to a for-loop with a 26 node project and see if it works. If not, resolve the issue and then go back to a parfor for a final test.
その他の回答 (1 件)
Edric Ellis
2025 年 1 月 30 日 12:01
I just came here to mention that we tried to improve the error reporting for this case. Here's what happens now, hopefully it makes more sense.
parfor k=1:Np
for i=1:(Nu-1)
for j=(i+1):Nu
if Sort(k,i)*Sort(k,j)==1 && Sort2(i,j)==0
Sort(k,:)=zeros;
flag=1;
break
end
end
if flag==1
flag=0;
break
end
end
if mod(count2,10E6)==0
count2-count1
count2
end
count2=count2+1;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Parallel Computing Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!