主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

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 对象或空双精度形式返回。

版本历史记录

在 R2022a 中推出