multi-level parallelism in Matlab (2013a)?
2 views (last 30 days)
Show older comments
Lukas Halagacka
on 6 Dec 2013
Commented: Lukas Halagacka
on 6 Dec 2013
Hello,
I am trying to solve a problem of efficient calculation of optical spectra (of some structures). The calculation process itself is represented by tens or hundred independent calculations (according to number of points in the optical spectra, number of wavelengths). The spectral interval is just a vector.
Until now I used parfor loop. I took the interval, split it to several subintervals (according to number of workers in matlabpool) and send it to workers by parfor loop. So, the subintervals were calculated in parallel. Finally I just glued partial results together. I choose "divide et impera" approach to reduce communication between nodes at cluster. If all subintervals have the same length and all nodes are free, the computation time of each subinterval problem is the same(almost).
But now, my problem increases in one dimension. I would like to compute several spectral problem in parallel. For exaple: 4 problems, each for the spectra with 1000points. What I would like to implement is code, which starts with 4 parallels workers (each for one problem). Than each worker solve its partial problem in parallel (lets say on 8 cpus). So finally I will use 1(initial master) + 4(submasters) + 4*8 = 37cpus (strange number, but it is just example).
So, my question is: Is it possible to implement such a parallelism in Matlab? Which construction should I use. Till now I have been working with parfor loops, but there is no way how to put one parfor inside another.
Thanks, Lukas Halagacka
0 Comments
Accepted Answer
Edric Ellis
on 6 Dec 2013
As you've discovered, you cannot nest parallelism with PARFOR. Depending on the amount of data transfer etc., you may find that "flattening" the problem is one way forward - i.e. convert the nested loops to a single flat PARFOR loop:
% from something like this
for r = 1:size(problems, 1)
for c = 1:size(problems, 2)
result(r, c) = solve(problems(r, c));
end
end
% to something more like this
parfor idx = 1:numel(problems)
result(idx) = solve(problems(idx));
end
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!