How to use parfor?

4 ビュー (過去 30 日間)
EM geo
EM geo 2019 年 3 月 25 日
コメント済み: EM geo 2019 年 4 月 1 日
Hi, i'm trying to use par-for in this code, but it matlab gives me this error: "Error: The variable D in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview"."
Anybody can explain me how does parfor works and how to modify this for properly?
clear; close all;
load('data_c2')
tic
% datas= Crosscurv,Elevation,Flowacc,Longcurv,Slope,Rv_mean,Rv_range_interq,Rv_median,Zero
D = [data_c2(:,2),data_c2(:,9),data_c2(:,5),data_c2(:,4),data_c2(:,7),data_c2(:,1),data_c2(:,3),data_c2(:,8)];
%D = Elevation, Zero, Slope, Longcurv, Rv_range_interq, Crosscurv, Flowacc, Rv_median
D(D == -9999) = NaN;
elevMax = max(D(:,1));
slopeMax = max(D(:,3));
longcurvMax = max(D(:,4));
crosscurvMax = max(D(:,6));
flowaccMax = max(D(:,7));
elevMin = min(D(:,1));
slopeMin = min(D(:,3));
longcurvMin = min(D(:,4));
crosscurvMin = min(D(:,6));
flowaccMin = min(D(:,7));
ticBytes(gcp);
PCtime = clock;
Date = strcat(num2str(PCtime(1)),'/',num2str(PCtime(2)),'/',...
num2str(PCtime(3)),'-',num2str(PCtime(4)),':',...
num2str(PCtime(5)));
text = ['Inizio loop ',' - ',Date];
disp(text)
parfor j= (1:length(D))
%max
if D(j,1) == elevMax;
D(j,1) = (elevMax - 1);
end
if D(j,3) == slopeMax;
D(j,3) = (slopeMax - 1);
end
if D(j,4) == longcurvMax;
D(j,4) = (longcurvMax - 1);
end
if D(j,6) == crosscurvMax;
D(j,6) = (crosscurvMax - 1);
end
if D(j,7) == flowaccMax;
D(j,7) = (flowaccMax - 1);
end
%min
if D(j,1) == elevMin;
D(j,1) = (elevMin + 0.1);
end
if D(j,3) == slopeMin;
D(j,3) = (slopeMin + 0.1);
end
if D(j,4) == longcurvMin;
D(j,4) = (longcurvMin + 0.1);
end
if D(j,6) == crosscurvMin;
D(j,6) = (crosscurvMin + 0.1);
end
if D(j,7) == flowaccMin;
D(j,7) = (flowaccMax + 0.1);
end
end
tocBytes(gcp)

採用された回答

Patel Mounika
Patel Mounika 2019 年 4 月 1 日
To solve the variable classification issues, make sure that your variables are uniquely classified and meet the respective category requirements. Here the variable D cannot be classified because the indexing of D is not same in all the places which is against the sliced variable category requirement.
Look into the below example.,
parfor i=1:10
b = A(1,i) + A(2,i)
end
Here A is not same in all the places. You can modify the code as follows to make it consistent.
A = [ 1 2 3 4 5 6 7 8 9 10;
10 20 30 40 50 60 70 80 90 100];
B = zeros(1,10);
parfor i=1:10
for n=1:2
B(i) = B(i)+A(n,i)
end
end
Refer to below documentation for more understanding.
Hope this helps.
  1 件のコメント
EM geo
EM geo 2019 年 4 月 1 日
really thanks Patel!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by