Automatic parfor without specify it
显示 更早的评论
Could Matlab automatically execute all the code that could be parallelized without modifying its syntax? What I want to say is that after starting the parpool all the forloops that are in my code will be automatically executed as a parfor.
3 个评论
Stephen23
2018-5-24
"Could Matlab automatically execute all the code that could be parallelized without modifying its syntax?"
Basically that would be normal MATLAB written using vectorized code:
etc.
Andrea Stevanato
2018-5-24
Stephen23
2018-5-24
@Andrea Stevanato: as I wrote, my comment applies to vectorized code. If it is possible to remove the loop and write those statement to use vectorized code then MATLAB will automatically use multicores/threads when possible/suitable, depending on the operations. My comment does not apply to for loops.
回答(1 个)
Rik
2018-5-24
0 个投票
No. The reason is that there are some restriction imposed on parfor-loops (mostly related to dynamic indexing), which are not imposed on normal for-loops.
Why don't you write your for-loops as parfor-loops yourself? Or do you want to run them as normal for-loops on machines without access to the parallel computing toolbox?
2 个评论
Andrea Stevanato
2018-5-24
Rik
2018-5-24
An ugly solution would be to have the code twice in your file: once with a for and the other time with a parfor. Then you put an if around it that checks if the parpool is started.
类别
在 帮助中心 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!