Is there a way to speed up the time for calling external program?
Show older comments
I am doing optimization problem. The objective function requires to call external program. But time for calling the program (0.1s) is much longer than the analysis of external program itself (0.01s). The optimization needs thousands of iteration to find optimum solution, so this takes hours. Is there a way to shorten the time for calling external program as it consumes most of required time?
Example of my script:
% Optimization
x = ga(@fun,100);
% Objective function
function y = fun(x)
% writing input for external program
fprintf(fopen('input.tcl','wt'),'%s\n',x);
% running external program
!opensees.exe analysis.tcl
% read analysis result
out = fscanf(fopen('output.tcl','r'),'%f',[100 Inf]);
% objective function
y = fun2(out);
end
6 Comments
Walter Roberson
on 28 Aug 2020
You could experiment with using System.Diagnostics.Process
Gifari Zulkarnaen
on 29 Aug 2020
per isakson
on 29 Aug 2020
google for "System.Diagnostics.Process"
Mario Malic
on 29 Aug 2020
Edited: Mario Malic
on 29 Aug 2020
Well, starting and closing a process that many times can take some time. During every iteration of ga, program gets opened and closed.
Maybe you can find open a program before you call the ga, and command it somehow to run the analysis.
Gifari Zulkarnaen
on 29 Aug 2020
Edited: Gifari Zulkarnaen
on 29 Aug 2020
Mario Malic
on 30 Aug 2020
I stumbled upon this, maybe this is the way to go.
Answers (0)
Categories
Find more on Debugging and Improving Code 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!