How to specify the number of labs in smpd?

조회 수: 1 (최근 30일)
Joe kiao
Joe kiao 2015년 6월 15일
댓글: micholeodon 2020년 10월 13일
My computer has 4 cores. When I use
smpd(3)
c=labindex;
if(c==1)
a=1;
elseif(c==2)
b=1;
elseif(c==3)
d=2;
end
end
Error: Could not create an SPMD block to match the requested size: 3. The parallel pool size is: 4, the active SPMD context is of size: 4.
So one can't specify the number of labs? Also smpd is based on shared memory like OpenMP?

채택된 답변

Edric Ellis
Edric Ellis 2015년 6월 16일
You're only allowed to have a single spmd context active at any given time. An spmd context is created when you open an spmd block, and remains active after completion of that block if you create any Composite or distributed objects. In your case, I presume you have some of these objects from a previous spmd block. Here's how you might hit the problem:
parpool('local', 4);
% The next line creates an spmd context of size 4:
spmd, x = 1; end
% The following line will throw an error because the Composite "x" is
% keeping the spmd context active:
spmd(3), y = 2; end
% We can close the active spmd context by clearing "x":
clear x
% This will now work correctly:
spmd(3), y = 2; end
  댓글 수: 1
micholeodon
micholeodon 2020년 10월 13일
Also avoid syntax with tildas like:
[outvar1, ~] = some_function(arg1, arg2);
do instead
outvar1 = some_function(arg1, arg2);
because it can trigger context error as well.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 15일
The message might be hinting that you already have an spmd pool open, and there isn't room for 3 more workers.
  댓글 수: 1
Edric Ellis
Edric Ellis 2015년 6월 16일
That's not quite right - see my answer for an explanation of the spmd active context.

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by