nested parallel optimization and parfor loops

4 次查看(过去 30 天)
I would like to run a code having this structure:
Parallel Optimization 1(Particle swarm):
--- Par for loop (length ~ 20):
--- --- Parallel Optimization 2(Particle swarm)
--- calculate a cost function based on the 20 results of the parfor loop and use it in the Parallel Optimization 1
Is it possible to connect to a cluster and make a such complicated nested parallel compuitation?
I am doing this:
Par for loop
Parallel Optimization 2(Particle swarm)
on my computer for now but i am not sure the particle swarms actually works in parallel.
Please tell me if it is doable. Thank you.

回答(1 个)

Walter Roberson
Walter Roberson 2024-8-26
If you specify the UseParallel option as true, then https://www.mathworks.com/help/gads/particle-swarm-options.html#bued1yt-1 calculations will be carried out using parallel processing -- parfor.
Within a parfor worker, parfor (and other parallel requests such as parfeval) are carried out in serial.
It is not possible to parfor within a parfor. (Well, it is possible, but the inner parfor will be executed in serial.)
Note that if you do not specify UseParallel, and instead specify UseVectorized then "Your objective function should accept an M-by-N matrix, where each row represents one particle, and return an M-by-1 vector of objective function values.". Your code might potentially use parfor during handling of that M-by-N matrix.

类别

Help CenterFile Exchange 中查找有关 Problem-Based Global Optimization Setup 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by