主要内容

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

keys

返回 ValueStoreFileStore 对象的所有键

自 R2022a 起

说明

keySet = keys(store) 返回一个字符串数组,其中包含 ValueStoreFileStore 对象 store 中的所有键。

示例

示例

全部折叠

对工作单元运行仿真并在客户端上检索作业的数据存储。数据存储是一个具有键值条目的 ValueStore 对象。显示此对象的键。

以下仿真寻找随机矩阵的逆并将结果存储在 ValueStore 对象中。

type workerInvCode
function workerInvCode(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) = inv(rand(models(i)));
end
end

使用默认集群配置文件在工作单元上运行批处理作业。

models = [4,8,32,20];
c = parcluster;
job = batch(c,@workerInvCode,0,{models});
wait(job);

检索客户端上的 ValueStore 对象。

store = job.ValueStore;

返回包含其键的字符串数组。

keySet = keys(store)
keySet = 4×1 string
    "result_1"
    "result_2"
    "result_3"
    "result_4"

在进程工作单元的并行池上运行仿真并检索客户端上的文件存储。文件存储是一个带有关键文件条目的 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

启动一个进程工作单元的并行池。

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);

显示 FileStore 对象的键。

keys(store)

输入参数

全部折叠

由 MATLAB 客户端和工作单元共享的数据或文件存储,指定为 ValueStoreFileStore 对象。

版本历史记录

在 R2022a 中推出