MATLAB Answers

Error in saving and load function for MAT file using parfeval

조회 수: 11(최근 30일)
Matlab
Matlab 5 Nov 2019
답변: Edric Ellis 6 Nov 2019
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 ?

  댓글 수: 0

로그인 to comment.

채택된 답변

Edric Ellis
Edric Ellis 6 Nov 2019
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

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by