getCurrentValueStore
説明
例
バッチ ジョブの実行とワーカーからのデータの取得
ワーカー上でシミュレーションを実行し、クライアント上でジョブのデータ ストレージを取得します。データ ストレージは、キーと値のエントリをもつ 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
出力引数
store
— MATLAB クライアントとワーカーで共有されるデータ ストレージ
ValueStore
オブジェクト | 空の double
MATLAB クライアントとワーカーで共有されるデータ ストレージ。ValueStore
オブジェクトまたは空の double として返されます。
バージョン履歴
R2022a で導入
参考
ValueStore
| isKey
| keys
| remove
| put
| get
| getCurrentFileStore
MATLAB コマンド
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは MATLAB コマンドをサポートしていません。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)