Main Content

getCurrentFileStore

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

R2022a 以降

説明

store = getCurrentFileStore は、ワーカー上の現在のジョブまたはプールの FileStore オブジェクトを取得します。store を使用して、ジョブがまだ実行中であっても後でクライアントによって取得できるファイルを、ワーカーからコピーします。getCurrentFileStore がワーカー以外の MATLAB® セッションで実行される場合は、空の結果が返されます。

すべて折りたたむ

ワーカー上でシミュレーションを実行し、クライアント上でジョブのファイル ストレージを取得します。ファイル ストレージは、キーとファイルのエントリをもつ 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              

出力引数

すべて折りたたむ

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

バージョン履歴

R2022a で導入