필터 지우기
필터 지우기

how to know if I can use parfor

조회 수: 2 (최근 30일)
mingcheng nie
mingcheng nie 2023년 1월 12일
댓글: Luca Ferro 2023년 1월 16일
hi there, I am a telecommunication student working on some matlab code. I have a group signal to noise ratio(SNR) and need to run a loop to go through all the SNR, e.g. substituting the SNR into some code. I gave an example here
for i=1:length(SNR)
a=b(SNR(i))%some code/function need to substitute the SNR
end
Can I use the parfor to speed up? how can I justify if I can use parfor or not.
  댓글 수: 1
Luca Ferro
Luca Ferro 2023년 1월 16일
if this is all you needed and my answer is satisfactory could you please accept it and close the question?

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

답변 (1개)

Luca Ferro
Luca Ferro 2023년 1월 12일
to use parfor() you need either a Matlab coder software (so standalone code) or the Parallel Computing Toolbox. Other than that i know no technical conditions that could limit its use.
Basically the syntax would be:
parfor (i=1:length(SNR),c),
a=b(SNR(i))%some code/function need to substitute the SNR
end
c is the number of cores you would like to use, if less cores than what you specify are available, it will use the most amount.
note that there is no guarantee that the operations in the parfor loop will be executed in order.
I think that in most cases it is overkill to use it and it would be better to optimize the code instead if possible. So if the only reason is to have the code run in a couple less seconds or minutes, i would not use it.
  댓글 수: 3
Luca Ferro
Luca Ferro 2023년 1월 13일
i think you can find an answer here
Walter Roberson
Walter Roberson 2023년 1월 13일
MATLAB recognizes parfor even if you do not have the toolbox. If you do not have the toolbox installed and licensed then it executes the iterations in serial in reverse order.

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by