keys
说明
示例
对工作单元运行仿真并在客户端上检索作业的数据存储。数据存储是一个具有键值条目的 ValueStore 对象。显示此对象的键。
以下仿真寻找随机矩阵的逆并将结果存储在 ValueStore 对象中。
type workerInvCodefunction 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 workerStatsCodefunction 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 客户端和工作单元共享的数据或文件存储,指定为 ValueStore 或 FileStore 对象。
版本历史记录
在 R2022a 中推出
另请参阅
ValueStore | FileStore | isKey | remove | put | get | copyFileToStore | copyFileFromStore
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)