メインコンテンツ

copyFileToStore

ローカル ファイル システムから FileStore オブジェクトにファイルをコピーする

R2022a 以降

説明

copyFileToStore(store,fileSet,keySet) は、対応するキー keySet を使用して、ローカル ファイル システム fileSet から store にファイルをコピーします。キーが既に store に存在する場合、copyFileToStore は指定されたキーに関連付けられたファイルを置き換えます。

すべて折りたたむ

プロセス ワーカーの並列プール上でシミュレーションを実行し、クライアント上のファイル ストレージを取得します。ファイル ストレージは、キーとファイルのエントリをもつ FileStore オブジェクトです。関数 copyFileToStore を使用して、対応するキーでの指定どおりに、このオブジェクトにファイルをコピーします。

次のシミュレーションでは、乱数行列の平均と標準偏差を求め、copyFileToStore を使用して結果を 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

プロセス ワーカーの並列プールを起動します。

pool = parpool("Processes");
Starting parallel pool (parpool) using the 'Processes' profile ...
Connected to the parallel pool (number of workers: 6).

このプールの FileStore を取得します。

store = pool.FileStore;

プール上でシミュレーションを実行します。

models = [4,8,32,20];
future = parfeval(@workerStatsCode,0,models);
wait(future);

入力引数

すべて折りたたむ

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

ローカル ファイル。文字ベクトル、string スカラー、string 配列、もしくは文字ベクトルまたは string の cell 配列として指定します。fileSetkeySet の要素数は同じでなければなりません。

例: ["/data/run.mat" "/tmp/run_log.txt"]

追加するキー。文字ベクトル、string スカラー、string 配列、もしくは文字ベクトルまたは string の cell 配列として指定します。fileSetkeySet の要素数は同じでなければなりません。

例: ["myDataKey" "myLogKey"]

バージョン履歴

R2022a で導入