MATLAB Answers


Error in saving and load function for MAT file using parfeval

Asked by Matlab on 5 Nov 2019
Latest activity Edited by Matlab on 7 Nov 2019 at 6:28
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 ?


Sign in to comment.

1 Answer

回答者: Edric Ellis
2019 年 11 月 6 日 10:08

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.

  1 Comment

2019 年 11 月 7 日 6:25
Thanks for the insight !
Checked the output for the snippet! Works well. I will put code in my implementation
x2 =
0.7922 0.0357 0.6787
0.9595 0.8491 0.7577
0.6557 0.9340 0.7431
>> x
x =
0.7922 0.0357 0.6787
0.9595 0.8491 0.7577
0.6557 0.9340 0.7431
I looked in the job monitor . I see stack error
>> delete(gcp('nocreate'))
Parallel pool using the 'local' profile is shutting down.
Task with properties:
ID: 1
State: finished
Function: @parallel.internal.cluster.executeScript
Parent: Job 170
StartDateTime: 07-Nov-2019 11:50:05
Running Duration: 0 days 0h 0m 2s
Error: Workers cannot execute parfeval or parfevalOnAll.
Error Stack: parfeval (line 58)
get_save_load_batch (line 6)
Warnings: none
Can you please explain why Stack Error is seen for parfeval ?

Sign in to comment.