parfeval evaluation is slow

5 次查看(过去 30 天)
Hi
I am using parfeval to calculate the eigenvalues of a matrix M with typical dimension of 1500x1500x100. The parfeval evaluations is slow since I read the output just after the evaluation of each matrix M(:,:,k) k=1,..,100. I want to store all the eigenvalues and eigenvectores in the variabel f and read the output after finishing the parfeval evaluation.
Current code:
eigMtr=complex(zeros(2*L,2*NumOfSlabs*L));
W=eigMtr;
W_1=complex(zeros(L,2*NumOfSlabs*L));W_2=W_1;
for k=1:NumOfSlabs
f=parfeval(@eig,3,M(:,:,k));
[Wt,Dt] = fetchOutputs(f);
start=1+(k-1)*2*L;stop=2*k*L;
eigMtr(1:2*L,start:stop)=sqrt(Dt);
W1=Wt(1:L,:);
W2=Wt(L+1:2*L,:);
W_1(:,start:stop)=W1;
W_2(:,start:stop)=W2;
W(1:L,start:stop)=W2;
W(L+1:2*L,start:stop)=W1;
end
I want to do something like this
for k=1:NumOfSlabs
f=parfeval(@eig,3,M(:,:,k));
end
for k=1:NumOfSlabs
[idx,Wt,Dt] = fetchNext(f)
start=1+(k-1)*2*L;stop=2*k*L;
eigMtr(1:2*L,start:stop)=sqrt(Dt);
W1=Wt(1:L,:);
W2=Wt(L+1:2*L,:);
W_1(:,start:stop)=W1;
W_2(:,start:stop)=W2;
W(1:L,start:stop)=W2;
W(L+1:2*L,start:stop)=W1;
end
Thanks for your help
Poul-Erik

采纳的回答

Walter Roberson
Walter Roberson 2025-4-11
Note the correction to the number of output arguements parameter in the parfeval() call
f = cell(NumOfSlabs, 1);
for k=1:NumOfSlabs
f{k} = parfeval(@eig,2,M(:,:,k));
end
wait(f{1});
for k=1:NumOfSlabs
[Wt,Dt] = fetchOutputs(f{k});
start=1+(k-1)*2*L; stop=2*k*L;
eigMtr(1:2*L,start:stop)=sqrt(Dt);
W1=Wt(1:L,:);
W2=Wt(L+1:2*L,:);
W_1(:,start:stop)=W1;
W_2(:,start:stop)=W2;
W(1:L,start:stop)=W2;
W(L+1:2*L,start:stop)=W1;
end
  8 个评论
Edric Ellis
Edric Ellis 2025-4-15
Ah, actually, the Parallel Computing Toolbox page for parfeval already does have examples showing arrays https://uk.mathworks.com/help/parallel-computing/parallel.pool.parfeval.html . @Walter Roberson were you looking at the page in the MATLAB doc? https://uk.mathworks.com/help/matlab/ref/parfeval.html .

请先登录,再进行评论。

更多回答(1 个)

Steven Lord
Steven Lord 2025-4-11
Have you compared the time of your parfeval call to the time required for a call to the pageeig function?
  1 个评论
Poul-Erik Hansen
Poul-Erik Hansen 2025-4-12
Yes, the two functions have similar speed but different cpuload.
pageeig cpu load 50%
parfeval cpuload 100 %

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by