Main Content

getCurrentValueStore

現在のジョブまたはプールのデータ ストレージを取得する

R2022a 以降

説明

store = getCurrentValueStore は、ワーカー上の現在のジョブまたはプールの ValueStore オブジェクトを取得します。store を使用して、ジョブの実行中にワーカーからクライアントへデータを送り返します。getCurrentValueStore がワーカー以外の MATLAB® セッションで実行される場合は、空の結果が返されます。

すべて折りたたむ

ワーカー上でシミュレーションを実行し、クライアント上でジョブのデータ ストレージを取得します。データ ストレージは、キーと値のエントリをもつ ValueStore オブジェクトです。

次のシミュレーションでは、乱数行列の特異値を求め、結果を ValueStore オブジェクトに保存します。

type workerSvdCode
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});

ジョブの実行中に、クライアント上で ValueStore オブジェクトを取得します。ジョブの進行状況を表示します。

store = job.ValueStore;
store.KeyUpdatedFcn = @handleNewEntry;
wait(job);
Result result_1 added
Progress update: 25.00 %
Result result_2 added
Progress update: 50.00 %
Result result_3 added
Progress update: 75.00 %
Result result_4 added
Progress update: 100.00 %

キー "result_1" で指定されたエントリ値をオブジェクトから取得します。

val1 = store("result_1")
val1 =

    4.3318
    1.2988
    1.1040
    0.8813
    0.5711
    0.3991
    0.2092
    0.1048

出力引数

すべて折りたたむ

MATLAB クライアントとワーカーで共有されるデータ ストレージ。ValueStore オブジェクトまたは空の double として返されます。

バージョン履歴

R2022a で導入