nested parallel optimization and parfor loops

1 Ansicht (letzte 30 Tage)
Vermeer Bonhomme
Vermeer Bonhomme am 26 Aug. 2024
Beantwortet: Walter Roberson am 26 Aug. 2024
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.

Antworten (1)

Walter Roberson
Walter Roberson am 26 Aug. 2024
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.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by