function workerSvdCode(models)
% Get the ValueStore of the current job
store = getCurrentValueStore;
for i = 1:numel(models)
% Store simulation results in the ValueStore object
pause(1)
key = strcat("result_",num2str(i));
store(key) = svd(rand(models(i)));
store("progress") = i/numel(models);
end
end
次のコールバック関数は、ValueStore オブジェクトにエントリが追加される際に実行されます。
type handleNewEntry
function handleNewEntry(store,key)
if strcmp(key,"progress")
fprintf("Progress update: %.2f %%\n",store(key)*100);
else
fprintf("Result %s added\n",key);
end
end
既定のクラスター プロファイルを使用して、ワーカー上でバッチ ジョブを実行します。
models = [8,16,32,20];
c = parcluster;
job = batch(c,@workerSvdCode,0,{models});