I need help regarding parfeval implementation with object handle. I have created an object handle, the member functions of which i want to run as parallel processes.
Mostrar comentarios más antiguos
I have created an object handle like this,
classdef example_class<handle
properties
A
B
end
methods
function h=example_class()
h.A=1;
h.B=1;
end
function multiply_A(h,data)
for m=1:10
h.A=h.A*data;
end
end
function add_B(h,data)
for m=1:10
h.B=h.B+data;
end
end
end
end
I want to run the methods multiply_A and add_B as parallel processes which can modify the properties of the original handle object i.e A and B. For this I am using parfeval as given in the below code,
clc;
clear all;
class1=example_class;
fout(1)=parfeval(@class1.multiply_A,0,2);
fout(2)=parfeval(@class1.add_B,0,5);
We can see that the methods dont have any output. They perform the operation on the handle objects only. But when i am running this code, the properties of the handle object 'class1' are not getting changed. A and B are initialized to 1 and they are still retaining the same value after parfeval ends. Anyone can give any idea, how to solve this so that A and B directly gets updated? It is to be noted that, the member functions should not return any value as that is the requirement of the application which i am working on.
1 comentario
Jeffrey Clark
el 20 de Dic. de 2022
@Sourav Chatterjee, Run function in background - MATLAB parfeval (mathworks.com) only schedules the function to execute, you need to Wait for futures to complete - MATLAB wait (mathworks.com) then look to see if there is a failure int the returned future (your fout). It wouldn't suprise me if you have an error due to the background threads possibly having their own address space.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!