2017-06-03 7 views
0

私のコードの一部をmatlabで並列化したいと思います。matlabでparforを使用する

v1=[1,3,6,8]; 
ggx=5.*ones(15,14); 
gax=ones(15,14); 
parfor i = 1:length(v1) 
m = v1(i); 
if m > 1 
gax(1:m-1,m-1) = ggx(1:m-1,m-1); 
end 
if m<nn 
gax(m+1:end,m) = ggx(m+1:end,m); 
end 
end 

しかし、エラーがある: エラー:一部以下の例のためのparfor内の変数GAXはMATLAB、「概要」のループのclassified.Seeパラレルすることはできません。

どのようにエラーを取り除くことができますか?他の有用な情報は、v1が反復要素を含まない増加ベクトルであることである。

+0

'parfor'の前に' gax'と 'gay'を初期化してみましたか?また、 'parfor'がこの場合にあなたのコードを最適化するのに役立つとは思いません。通常の 'for'ループだけを使う方が良いでしょう。 – kedarps

+0

はい私はparforの前にそれらの値を与えました。 @kedarps –

+0

これは、スライスされた変数インデックスの問題のようです。[here](https://www.mathworks.com/help/distcomp/troubleshoot-variables-in-parfor-loops.html)を参照してください。 – kedarps

答えて

1

エラーメッセージに記載されているとおり、Sliced Variable ruleに従う必要があります。 gaxgayの両方が、Fixed Index ListingForm of Indexingという規則を破ります。また、文書内のスライスされていない変数の例として、この例のA(i,20:30,end) % 20:30 not scalarを使用できます。

したがって、parforのすべての部分を適切な並列計算に変更する必要があります。つまり、ループ変数に基づいてメソッドを並列化できる適切な並列アルゴリズムを設計する必要があります。

Type of First-Level Indexing — The first level of indexing is either parentheses,(), or braces, {}.

Fixed Index Listing — Within the first-level parentheses 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 side of the assignment cannot be [] or '', because these operators attempt to delete elements.

+0

"つまり、ループ変数に基づいてメソッドを並列化できる適切な並列アルゴリズムを設計する必要があります。質問はそれを行う方法です –

+0

私の意見はあなたがここでそれを行うことはできませんです! – OmG

+0

私はそれを忘れていました、v1は反復要素を持たない増加するベクトルです。この場合、parforの使い方を知っていますか? –

関連する問題