copyFileFromStore
Description
Examples
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. Copy files from this object as specified by their corresponding keys using the copyFileFromStore
function.
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
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.
store = pool.FileStore;
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.
keys(store)
ans = 4×1 string
"result_1"
"result_2"
"result_3"
"result_4"
Copy files from the file storage as specified by the corresponding keys "result_1"
and "result_2"
to the local files "run_1.mat"
and "run_2.mat"
.
copyFileFromStore(store,["result_1" "result_2"],["run_1.mat" "run_2.mat"])
Display all the information on the variables stored in the local files.
whos -file 'run_1.mat'
Name Size Bytes Class Attributes M 1x4 32 double S 1x4 32 double
whos -file 'run_2.mat'
Name Size Bytes Class Attributes M 1x8 64 double S 1x8 64 double
Input Arguments
File storage shared by MATLAB clients and workers, specified as a FileStore
object.
Keys to copy, specified as a character vector, string scalar, string array, or cell
array of character vectors or strings. keySet
and
fileSet
must have the same number of elements.
Example: ["myDataKey" "myLogKey"]
Local files, specified as a character vector, string scalar, string array, or cell
array of character vectors or strings. keySet
and
fileSet
must have the same number of elements.
Example: ["/data/run.mat" "/tmp/run_log.txt"]
Version History
Introduced in R2022a
See Also
FileStore
| isKey
| keys
| remove
| copyFileToStore
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)