Error in saving and load function for MAT file using parfeval

10 ビュー (過去 30 日間)
Life is Wonderful
Life is Wonderful 2019 年 11 月 5 日
回答済み: Edric Ellis 2019 年 11 月 6 日
I want to save and load the data from MAT file using parfeval. Here is my code
Files = 'matfile.mat';
f = parfeval(@save,1,fullfile(yourfolder,Files),'Files','Content','joinedtimetable','-v7.3');
data = fetchOutputs(f);
I am getting error
ID: 121
Function: @save
CreateDateTime: 05-Nov-2019 17:02:14
StartDateTime: 05-Nov-2019 17:02:14
Running Duration: 0 days 0h 0m 0s
State: finished (unread)
Error: No workers are available for FevalQueue execution.
For loading MAT file
f = parfeval(@load,1,fullfile(yourfolder,Files))
data = fetchOutputs(f);
I need help here ?

採用された回答

Edric Ellis
Edric Ellis 2019 年 11 月 6 日
The error you're receiving is a bit surprising - that probably means that all your workers crashed somehow.
In any case, the syntax you're using to combine parfeval with save is not right. Firstly, save doesn't return any output arguments, so you need to specify 0 for the number of outputs. Secondly, and more importantly, save accepts the names of variables that you want to save, and extracts the values from the enclosing workspace. This makes it tricky to use with parfeval. You basically need to wrap the call to save in another function. You probably then want to wrap load in a similar function. Like this:
% Make some data
x = rand(3);
% Choose a filename
fileName = fullfile(tempdir, 'file.mat');
% Use 'mySave' to save the data
f = parfeval(@mySave, 0, fileName, x);
% Wait for 'mySave' to complete before attempting to load
wait(f);
% Load the data from the file
f = parfeval(@myLoad, 1, fileName);
x2 = fetchOutputs(f);
% Check we got the correct value
assert(isequal(x, x2))
function mySave(fname, value)
save(fname, 'value');
end
function value = myLoad(fname)
data = load(fname);
value = data.value;
end
This shows you how to save and load on the workers. It's not clear to me that this is actually a terribly useful thing to do though - you might well find that it takes so long to send the data to the worker prior to saving it that it doesn't gain you any benefit. Saving data from the workers is probably only useful if you're doing other work prior to the save.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAsynchronous Parallel Programming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by