getCurrentFileStore
説明
例
バッチ ジョブの実行とワーカーからのファイルの取得
ワーカー上でシミュレーションを実行し、クライアント上でジョブのファイル ストレージを取得します。ファイル ストレージは、キーとファイルのエントリをもつ FileStore
オブジェクトです。
次のシミュレーションでは、乱数行列の平均と標準偏差を求め、結果を FileStore
オブジェクトに保存します。
type workerStatsCode
function workerStatsCode(models) % Get the FileStore of the current job store = getCurrentFileStore; for i = 1:numel(models) % Compute the average and standard deviation of random matrices A = rand(models(i)); M = mean(A); S = std(A); % Save simulation results in temporary files sourceTempFile = strcat(tempname("C:\myTempFolder"),".mat"); save(sourceTempFile,"M","S"); % Copy files to FileStore object as key-file pairs key = strcat("result_",num2str(i)); copyFileToStore(store,sourceTempFile,key); end end
次のコールバック関数は、FileStore
オブジェクトにファイルがコピーされる際に実行されます。
type fileNewEntry
function fileNewEntry(store,key) destination = strcat(key,".mat"); fprintf("Result %s added. Copying to local file system: %s\n",key,destination); copyFileFromStore(store,key,destination); end
既定のクラスター プロファイルを使用して、ワーカー上でバッチ ジョブを実行します。
models = [4,8,32,20]; c = parcluster; job = batch(c,@workerStatsCode,0,{models});
ジョブの実行中に、クライアント上で FileStore
オブジェクトを取得します。ジョブの進行状況を表示します。
store = job.FileStore; store.KeyUpdatedFcn = @fileNewEntry; wait(job);
Result result_1 added. Copying to local file system: result_1.mat Result result_2 added. Copying to local file system: result_2.mat Result result_3 added. Copying to local file system: result_3.mat Result result_4 added. Copying to local file system: result_4.mat
ファイル "result_3.mat"
に保存されている変数に関する情報をすべて表示します。
whos -file 'result_3.mat'
Name Size Bytes Class Attributes M 1x32 256 double S 1x32 256 double
出力引数
store
— MATLAB クライアントとワーカーで共有されるファイル ストレージ
FileStore
オブジェクト | 空の double
MATLAB クライアントとワーカーで共有されるファイル ストレージ。FileStore
オブジェクトまたは空の double として返されます。
バージョン履歴
R2022a で導入
参考
FileStore
| isKey
| keys
| remove
| copyFileToStore
| copyFileFromStore
| getCurrentValueStore
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)