필터 지우기
필터 지우기

Automatic parfor without specify it

조회 수: 1 (최근 30일)
Andrea Stevanato
Andrea Stevanato 2018년 5월 24일
댓글: Stephen23 2018년 5월 24일
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
Andrea Stevanato
Andrea Stevanato 2018년 5월 24일
Mmm i don't know if i understood correctly if i have this pices of code
for index = 1:size(something)
statement;
statement;
end
this would be parallized automatically by matlab or i need to change for with parfor? This is just an exemple, so what i would is i start parpool and then, when possible, all code will be parallized.
Stephen23
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
Rik 2018년 5월 24일
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
Andrea Stevanato 2018년 5월 24일
Exactly i want use parfor-loops only in some case and run code without parfor in other case. Or bettere I would parallelize (for, etc...) only when i start parpool "manually"
Rik
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by