Building an array using parfor

1 回表示 (過去 30 日間)
Moiz
Moiz 2016 年 1 月 24 日
コメント済み: Walter Roberson 2016 年 1 月 25 日
Hi,
I am building an array using parfor in the following fashion :
parfor ifreq = 1:80
for iSig = 1:140
[SigVal,~] = somefunction(NecessaryInputs)
AllSig(ifreq,iSig,:) = SigVal;
end
end
However this is throwing an error that the variable AllSig cannot be classified. Any ideas how to get this to work ?

回答 (2 件)

Edric Ellis
Edric Ellis 2016 年 1 月 25 日
What version of MATLAB are you using? I tried this in R2015b, and it worked as expected:
parfor ifreq = 1:80
for iSig = 1:140
SigVal = rand(3,1);
AllSig(ifreq,iSig,:) = SigVal;
end
end
  1 件のコメント
Moiz
Moiz 2016 年 1 月 25 日
I am using R2014b

サインインしてコメントする。


Walter Roberson
Walter Roberson 2016 年 1 月 25 日
parfor ifreq = 1:80
SigVal = zeros(140, 3); %for example
for iSig = 1:140
[SigVal(iSig, :),~] = somefunction(NecessaryInputs)
end
AllSig(ifreq,:,:) = SigVal;
end
  2 件のコメント
Moiz
Moiz 2016 年 1 月 25 日
Hi Walter,
This works except that I found parfor to take a huge amount of time (more than the regular for loop). So I am not sure what was going on..
Walter Roberson
Walter Roberson 2016 年 1 月 25 日
parfor is not necessarily faster, due to the various overheads involved. Also because the workers are restricted to one CPU each whereas non-parallel array computations that are "big enough" get sent to BLAS or LAPACK which operates on all CPUs on the host. Therefore any one computation can take several times longer in parallel.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by