Saving and resuming the parfor states

8 views (last 30 days)
Abdulllah
Abdulllah on 26 Aug 2019
Commented: Nicolas B. on 27 Aug 2019
Is it possible to save the states of parfor loop, stop/break and restart from the same state. For example, in may case some time Windows crashes and I can not run the simulaiton from the same state, I have to run from initial level. In a simple for loop, I can save the variable i and ourval then I can run the for loop. In the code shown below, I have only variable i chaning in the parfor. Can I save parfor states after some interval and after restarting Matlab I can have all the variables in the wokspace resume parfor from same states.
% cubeL=51;
% XYZw=[90 100 108];
% P_labs, xyz nx3 matrix
% some_function is a function
ourval=zeros(size(xyz));
parfor i=1:cubeL*cubeL*cubeL
ourval(i,:)= some_function(xyz(i,:),P_labs,rgb,XYZw);
endd

Accepted Answer

Nicolas B.
Nicolas B. on 26 Aug 2019
Hi Imran,
I would suggest 2 solutions:
  1. at each iteration of your parfor loop, you log your progress into a file and then, if MATLAB or Windows crashes, you read that file.
  2. you use the DataQueue class to send back data to your main MATLAB process and you log the information in a file (see this documentation).
Does it helps you?
  2 Comments
Nicolas B.
Nicolas B. on 27 Aug 2019
Hi,
I haven't much time so I haven't tested your code. However, when calling a parfor loop, you must already have created the data at the right size (no resizing in parfor for common data). So try to create ourval before parfor.
For the code 2, try to write send(q, num2str(i)) in the loop instead of what you have. If what I suspect is right, I think that it should call disp(i) at the end of each loop.
I let you try. If I find time this afternoon, I will try to run your code.
Regards

Sign in to comment.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by