필터 지우기
필터 지우기

How to implement semaphore concept in Matlab?

조회 수: 10 (최근 30일)
DhanaLakshmiR
DhanaLakshmiR 2018년 2월 27일
댓글: Walter Roberson 2018년 2월 27일
Is this possible to implement semaphore concept in matlab? Kindly give some explanation which will be very useful for my project.
  댓글 수: 2
Rik
Rik 2018년 2월 27일
Probably. We are volunteers, not mind readers. If you want a useful explanation, you'll have to describe your project at the very least. I would advise you to read the following two links, and come back when you have an actual answerable question. Link 1 and link 2.
DhanaLakshmiR
DhanaLakshmiR 2018년 2월 27일
편집: DhanaLakshmiR 2018년 2월 27일
Apologize for my previous question. I am having two m-files which are running simultaneously.
% First mfile
function[x1] =fcn1(x,y)
for i=1:10
y=y+40;
x1=x+y;
end
%second mfile
function[x3]= fcn2(y2)
for j=10
y3=y2+4;
x3=y2+y3;
end
%parallel code
delete(gcp);
parpool('AttachedFiles',{'fcn1.m','fcn2.m'})
addpath('C:\Users\SUBATHRA\Documents\MATLAB');
poolobj = gcp('nocreate');
if isempty(poolobj)
poolsize = 0;
else
poolsize = poolobj.NumWorkers
end
spmd
for i=1:.1:10
if labindex == 1
fcn1_output = fcn1(20,5)
labSend(fcn1_output, 2);
else
fcn2_parameters = labReceive()
fcn2_output = fcn2(fcn2_parameters)
end
end
end
Because of for loop ,the output is coming after the final iteration of the loop.But i need the output for each and every iteration.when fcn1 is sending values fcn2 have to wait until the values are received after that i have to work based on the code. So that i thought semaphore concept will resolve the problem. Kindly give answers. If my question is not valid apologize me and ask i will explain.

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 27일
You have no parallel code as you have no parfor or spmd or batch or parfeval or parfevalOnAll
You use labindex which is not valid for parfor but it is valid for spmd. If you are using spmd then the tool for semaphore is effectively to use labBarrier()
  댓글 수: 2
DhanaLakshmiR
DhanaLakshmiR 2018년 2월 27일
i have created this for parallel running. I have missed spmd. Now the code has changed.
Walter Roberson
Walter Roberson 2018년 2월 27일
You appear to expect exactly two workers. You should specify the number of workers when you create the parpool as the default is the number of physical cores and even if your setup only has two cores other people running the code might have more.

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

카테고리

Help CenterFile Exchange에서 Distributed Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by