Is parallel processing possible in optimization with App Designer
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sherman Marcus
el 24 de Jul. de 2024
Editada: Walter Roberson
el 25 de Jul. de 2024
I have an app that I developed in App Designer which performs optimization with the aid of the Matlab function lsqnonlin. A snippet:
methods (access = private)
function x=doOptimize(app,x0,lb,ub,options)
f=@(xx)Fun(app,xx);
x=lsqnonlin(f,x0,lb,ub,options);
end
function ff=Fun(app,x)
ff=someFunction(app,x);
end
end
The “someFunction” is a very complex function which utilizes many app properties and methods. The app works fine. However, I would like to take advantage of parallel processing by setting options.UseParallel = true. Doing this causes all kinds of warnings and errors, evidently in accordance with previous posts that stated that the save and load performed by the parallel workers are incompatible with app objects. My question is this: Is there any work-around for this problem? Of course, if app could be excluded altogether from the function Fun, then access=Static can be used. But in this case app is completely intertwined in the calculations. On the other hand, for the parallel processing, why should it be necessary to save the app variable? Since app-related variables only appear in someFunction, would it be possible to remove all references to app in the snippet, define access as Static, and pass app to someFunction as a global variable? Could this trick the parallel workers into thinking that there are no app objects around? (I’m willing to try anything.)
2 comentarios
Karan Singh
el 25 de Jul. de 2024
@Sherman Marcus I belive the approach you are suggesting is possible have you tried it out? One approach is to pass the necessary data from the app object as separate variables to the someFunction. Instead of passing the app object, pass the necessary data as separate arguments to someFunction.
methods (Access = private, Static)
function x = doOptimize(x0, lb, ub, options, appData)
f = @(xx) Fun(xx, appData);
x = lsqnonlin(f, x0, lb, ub, options);
end
function ff = Fun(x, appData)
ff = someFunction(x, appData);
end
function ff = someFunction(x, appData)
end
end
% Call doOptimize with additional appData argument
appData = struct('data1', app.data1, 'data2', app.data2, ...); % Add all necessary data
x = doOptimize(x0, lb, ub, options, appData);
Respuesta aceptada
Walter Roberson
el 25 de Jul. de 2024
Editada: Walter Roberson
el 25 de Jul. de 2024
My question is this: Is there any work-around for this problem?
No, there is no workaround.
Since app-related variables only appear in someFunction, would it be possible to remove all references to app in the snippet, define access as Static, and pass app to someFunction as a global variable?
No, the value of global variables is not transfered to parallel workers.
The closest approach to that would be parallel.pool.Constant
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!