Main Content

getCurrentValueStore

Get data storage of current job or pool

Description

example

store = getCurrentValueStore gets the ValueStore object of the current job or pool on a worker. Use the store to send data from workers back to clients during the execution of a job. If getCurrentValueStore is executed in a MATLAB® session that is not a worker, you get an empty result.

Examples

collapse all

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.

The following simulation finds the singular values of random matrices and stores the results in the ValueStore object.

type workerSvdCode
function workerSvdCode(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) = svd(rand(models(i)));
    store("progress") = i/numel(models);
end
end

The following callback function is executed when an entry is added to the ValueStore object.

type handleNewEntry
function handleNewEntry(store,key)
if strcmp(key,"progress")
    fprintf("Progress update: %.2f %%\n",store(key)*100);
else
    fprintf("Result %s added\n",key);
end
end

Run a batch job on workers using the default cluster profile.

models = [8,16,32,20];
c = parcluster;
job = batch(c,@workerSvdCode,0,{models});

Retrieve the ValueStore object on the client while the job is still running. Show the progress of the job.

store = job.ValueStore;
store.KeyUpdatedFcn = @handleNewEntry;
wait(job);
Result result_1 added
Progress update: 25.00 %
Result result_2 added
Progress update: 50.00 %
Result result_3 added
Progress update: 75.00 %
Result result_4 added
Progress update: 100.00 %

Get the entry value as specified by the key "result_1" from the object.

val1 = store("result_1")
val1 =

    4.3318
    1.2988
    1.1040
    0.8813
    0.5711
    0.3991
    0.2092
    0.1048

Output Arguments

collapse all

Data storage shared by MATLAB clients and workers, returned as a ValueStore object or an empty double.

Version History

Introduced in R2022a