Error in saving and load function for MAT file using parfeval

9 views (last 30 days)
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 ?

Accepted Answer

Edric Ellis
Edric Ellis on 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
% 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');
function value = myLoad(fname)
data = load(fname);
value = data.value;
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.

More Answers (0)


Find more on Background Processing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by