私はこのような基本的なコードを持っています:
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
変数名がすべての反復で同じであるため、競合が発生しますか?
いいえ、すべてのワーカーには固有の名前空間があります。
ただし、ワーカーはクライアントに表示される 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