2016-05-10 31 views
0

時間のかかるメインループを並列化したいネストループのある(非常に長い)Matlabコードがあります。これは私のコードのドラフトでMatlabの並列処理中にエラーが発生しました

Error: The variable DMax in a `parfor` cannot be classified. 
See Parallel for Loops in MATLAB, "Overview". 

::(明らかに)私に問題を与える唯一の変数は、私はエラーを取得DMax、ある問題が邪魔にある私は推測

t0=matrix (Maxiter,1); % This is a big matrix whose dimensions are reported in brachets 
Maxiter = 1E6; 
DMax = zeros(Maxiter,40); 
% Other Stuff 
for j=1:269 
    % Do more stuff 
    for soil=1:4 
     parfor i =1:Maxiter   
      k(i,soil) = a %k is a real number 
      a(i,soil) = b %similar to k 
      % Do a lot of stuff 
      for t= (floor(t0(i,soil))+1):40 
       DMax(i,t) = k(i,soil)*((t-t0(i,soil))^a(i,soil)); 
       % Do some more stuff 
      end 
     end 
    end 
end 
for time=1:40 
    % Do the final stuff 
end 

をI私はそれがもっと正確になるかもしれないのか分かりません。私はすでにウェブを見ていましたが、それほど満足のいく結果はありませんでした。

答えて

0

documentationには、parfor内の各変数がいくつかのタイプの1つに分類されなければならないことが非常に明確に記載されています。あなたDMax変数は、スライス変数(そのセグメントループの異なる繰り返しによって操作さ配列)であるべきであるが、順にall the following conditions must hold、このように分類される:

  • Type of First-Level Indexing — The first level of indexing is either parentheses,(), or braces, {}.
  • Fixed Index Listing — Within the first-level parenthesis or braces, the list of indices is the same for all occurrences of a given variable.
  • Form of Indexing — Within the list of indices for the variable, exactly one index involves the loop variable.
  • Shape of Array — The array maintains a constant shape. In assigning to a sliced variable, the right-hand side of the assignment cannot be [] or '', because these operators attempt to
    delete elements.

明らかに、が固定インデックスリストDMax(i,t)と表示されているので、リストプロパティは保持されません。ここで、tは値を変更します。ドキュメントに記載されている例と同じですが、注意してください。そのため、一時的な変数を内側のループの内側で使用してから、全体の行をDMaxに戻して回避する方法があります。

また、変数aはいずれのカテゴリにも分類できません。これはあなたの例では全く定義されていないことは言及していません。ガイドを慎重に読んで、カテゴリの1つに分類できることを確認してください。必要に応じてコードを書き換えます(例:新しい一時変数を導入する。ここで

DMax使用法が修正されたコードです:

Maxiter = 1E6; 
t0 = randn(Maxiter,1); % This is a big matrix whose dimensions are reported in brachets 
DMax = zeros(Maxiter,40); 
% Other Stuff 
for j = 1:269 
    % Do more stuff 
    for soil = 1:4 
     parfor i = 1:Maxiter   
      k(i,soil) = a %k is a real number 
      a(i,soil) = b %similar to k 
      % Do a lot of stuff 
      tmp = zeros(1,40); 
      for t = (floor(t0(i,soil))+1):40 
       tmp(t) = k(i,soil)*((t-t0(i,soil))^a(i,soil)); 
       % Do some more stuff 
      end 
      DMax(i,:) = tmp; 
     end 
    end 
end 
for time = 1:40 
    % Do the final stuff 
end 
+0

はコードがエラーなしで実行される今、あなたの答えをいただき、ありがとうございます。私が尋ねた質問をお詫び申し上げますが、私はMathworksの説明がまったくわからないと言わざるを得ない。それでも、ありがとうございました。ところで、あなたはforループで 'tmp(t)'を忘れてしまったと思います。それはそれを実行している方法であり、以前のコードを完全に置き換えます。 – Patapunfate

+0

正解、私の答えを修正しました。喜んで助けた) –

関連する問題