getCurrentFileStore - Get file storage of current job or pool - MATLAB (original) (raw)
Main Content
Get file storage of current job or pool
Since R2022a
Syntax
Description
[store](#mw%5Fbe892b2b-10f9-4f7e-a777-a47e95a9ff63) = getCurrentFileStore
gets theFileStore
object of the current job or pool on a worker. Use thestore
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.
Examples
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.
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.
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
File storage shared by MATLAB clients and workers, returned as a FileStore
object or an empty double.
Version History
Introduced in R2022a