How to use a MATLAB optimization function to do optimization using different PCs

4 views (last 30 days)
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.

Accepted Answer

Himanshu
Himanshu on 29 Aug 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:
  1. Ensure that you have access to the Parallel Computing Toolbox and that you have set up your MATLAB environment to support parallel execution.
  2. Modify your optimization function "Fun_opt" to accept a parameter that will determine which initial guess to use in each parallel iteration.
  3. 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.

More Answers (0)

Categories

Find more on Data Export to MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!