Main Content

getCurrentFileStore

Get file storage of current job or pool

Since R2022a

Description

store = getCurrentFileStore gets the FileStore object of the current job or pool on a worker. Use the store to copy files from workers that can be retrieved by clients later, even while the job is still running. If getCurrentFileStore is executed in a MATLAB® session that is not a worker, you get an empty result.

example

Examples

collapse all

Run a simulation on workers and retrieve the file storage of the job on a client. The file storage is a FileStore object with key-file entries.

The following simulation finds the average and standard deviation of random matrices and stores the results in the FileStore object.

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

The following callback function is executed when a file is copied to the FileStore object.

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

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

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

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

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

Display all the information on the variables stored in the file "result_3.mat".

whos -file 'result_3.mat'
  Name      Size            Bytes  Class     Attributes

  M         1x32              256  double              
  S         1x32              256  double              

Output Arguments

collapse all

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

Version History

Introduced in R2022a