isKey - Determine if ValueStore or FileStore object
contains keys - MATLAB ([original](http://www.mathworks.com/access/helpdesk/help/parallel-computing/parallel.valuestore.iskey.html)) ([raw](?raw))
Determine if ValueStore
or FileStore
object contains keys
Since R2022a
Syntax
Description
`TF` = isKey([store](#mw%5F2663d5f5-9aaf-4a8b-8c53-4cbbceecab3f),[keySet](#mw%5F0d10dd4b-0a0a-446e-9809-c5643062023e))
returns a logical array containing 1
(true
) for each key as specified in keySet
that exists in theValueStore
or FileStore
objectstore
, and 0
(false
) otherwise.
Examples
Check Keys of ValueStore
Object
Run a simulation on workers and retrieve the data storage of the job on a client. The data storage is a ValueStore
object with key-value entries. Check whether the specified keys exist in this object.
The following simulation finds the inverse of random matrices and stores the results in the ValueStore
object.
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
Run a batch job on workers using the default cluster profile.
models = [4,8,32,20]; c = parcluster; job = batch(c,@workerInvCode,0,{models}); wait(job);
Retrieve the ValueStore
object on the client.
Show the keys of this object.
ans = 4×1 string "result_1" "result_2" "result_3" "result_4"
Check whether the following specified keys exist in the ValueStore
object.
TF = isKey(store,["result_2", "result_5", "result_3"])
TF = 1×3 logical array
1 0 1
Check Keys of FileStore
Object
Run a simulation on a parallel pool of process workers and retrieve the file storage on a client. The file storage is a FileStore
object with key-file entries. Check whether the specified keys exist in this object.
The following simulation finds the average and standard deviation of random matrices and stores the results in the FileStore
object.
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
Start a parallel pool of process workers.
pool = parpool('Processes');
Starting parallel pool (parpool) using the 'Processes' profile ... Connected to the parallel pool (number of workers: 6).
Get the FileStore
for this pool.
Run the simulation on the pool.
models = [4,8,32,20]; future = parfeval(@workerStatsCode,0,models); wait(future);
Show the keys of the FileStore
object.
Check whether the following specified keys exist in the FileStore
object.
TF = isKey(store,["result_2", "result_5", "result_3"])
Input Arguments
store
— Data or file storage shared by MATLAB® clients and workers
ValueStore
object | FileStore
object
Data or file storage shared by MATLAB clients and workers, specified as a ValueStore
orFileStore
object.
keySet
— Keys to search for
character vector | string scalar | string array | cell array of character vectors or strings
Keys to search for, specified as a character vector, string scalar, string array, or cell array of character vectors or strings.
Version History
Introduced in R2022a