simulation based optimization using parallel computing, which one to be added to workers folders?

조회 수: 3 (최근 30일)
Hi everyone, im using GA and surrogate optimization to optimize a model created by external software (Finite element analysis). To speed up my optimization i also use parallel computing toolbox. After studying these two examples below i realize i needed to load my external software model into four woker folders in the beginning (because im using 4-core computer). After done this step, my questions are:
1) How to open the specific model based on the specific worker in my objective function? For example model 1 is located in folder 'worker 1' so in my objective function do i need to obtain the number of worker first and then open the related model? (spmd not working in my objective function, dont know why)
2)The model simulation results are automatically generated in the same folder where the relevant model located by the time the simulation is finished, and i need to read the results to calculate my optimization output and constraints. Same problem ouucr: how to obtain the number of worker and read the related model's results?
3)Except for my external software model, is there any other .m files i should add to the workers folders?
Thank you!

답변 (1개)

Edric Ellis
Edric Ellis 2019년 5월 1일
You haven't really given enough detail for me to give you particularly concrete suggestions, but here are a few thoughts anyway...
Firstly, if you're using "local" workers (i.e. parpool('local',4)) then you shouldn't normally have to add any MATLAB code to the workers - they will generally pick everything up automatically.
Secondly, I would suggest trying something like this:
workerBaseFolder = 'path/to/base';
parfor simIdx = 1:4
workerFolder = fullfile(workerBaseFolder, sprintf('worker %d', simIdx));
% Remember original working directory
oldWd = pwd;
% Change to the "worker" directory for this loop iteration
cd(workerFolder);
% Run the simulation
runSimulation(. . .);
% Restore the working directory
cd(oldWd);
end

카테고리

Help CenterFile Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by