0

私はこのような基本的なコードを持っています:

parfor i=1:8
    [t,y]=ode15s(@rate,tspan,cin,options,i); % the option i is evaluated in the rate function
    figure(1)
    subplot(3,3,i+1)
    plot(t,y)
    hold on
end

y変数名がすべての反復で同じであるため、競合が発生しますか?

4

2 に答える 2

3

いいえ、すべてのワーカーには固有の名前空間があります。

ただし、ワーカーはクライアントに表示される Figure を開くことができないため (@Edric のリマインダーに感謝します)、呼び出しの後のすべてode15sが有用な結果を生成しません。

プロットをparforループの外に移動するには、次のようにします (より効率的な解決策があり、これは確実に機能します)。

tCell = cell(8,1);
yCell = cell(8,1);
parfor i=1:8
    [tCell{i},yCell{i}]=ode15s(@rate,tspan,cin,options,i); % the option i is evaluated in the rate function

end

figure(1)
for i=1:8
   subplot(3,3,i+1)
   plot(tCell{i},yCell{i})
   hold on
end
于 2013-11-11T11:27:02.357 に答える