How to use a MATLAB optimization function to do optimization using different PCs
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Azadi Tabar
el 9 de Nov. de 2022
Respondida: Himanshu
el 29 de Ag. de 2023
I am using "ga" function of MATLAB to Run an optimization. The optimization function is as follow:
function [Obj] = Fun_opt (x0)
...
e.Run('Sheet1.FirstExample');
...
end
description of the function: simply it opens excel, writes some data in excel, runs a Macro within the excel, receives some data from excel (objective function).
The macro file is as follow:
Sub FirstExample()
Dim objADS
....
objADS.Application.Simulation.Run (True)
....
end Sub
The Macro file also simply goes in main simulation software and writes guess data of ga (x0) function and then runs the simulator, and then receive some data from simulator (objective function).
In normal ways, ga sends first guess (x0) to excel (macro) and macro use this guess and runs the simulator. Then. it recieves objective function which will be read by matlab. This single process continues to reach the minimum of the objective function based on the optimization algorithm. Now, I would like ga (or even any other possible function), send different guess to different computers to do simulation at the same time. For example, I have 5 PCs, then the optimization function produces 5 different x0, and runs the simulator on 5 PCs. Again the same process goes on and on. This way my simulation speed will increase.
I should mention I have to do it on different computers as my the main simulator (Aspen) licence does not allow it to be open in the same computer twice.
2 comentarios
Respuesta aceptada
Himanshu
el 29 de Ag. de 2023
Hello Mohammad,
I understand that you are trying to parallelize your optimization process using MATLAB's "ga" function and distribute different initial guesses to multiple computers for concurrent simulation.
MATLAB provides some tools that can help you achieve parallel execution. You can use MATLAB's Parallel Computing Toolbox and "parfor" function (parallel for loop).
You can follow the below steps to parallelize your optimization process:
- Ensure that you have access to the Parallel Computing Toolbox and that you have set up your MATLAB environment to support parallel execution.
- Modify your optimization function "Fun_opt" to accept a parameter that will determine which initial guess to use in each parallel iteration.
- Replace your optimization code's regular "for" loop with a "parfor" loop. The "parfor" loop will distribute different guesses to different MATLAB workers, each executing the simulation independently.
You can refer to the below documentation to learn more about the "ga" function, the "parfor" function and the Parallel Computing Toolbox in MATLAB.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Export to MATLAB 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!