Parallel computing problem

조회 수: 5 (최근 30일)
Sampath reddy
Sampath reddy 2012년 3월 22일
I have 3 programs to run in parallel, each on one core on my quad core processor. For this i'm using jobs and tasks method. After every iteration of the loop in the 3 functions, i have to use data from each program( that are running parallel on the cores individually) and calculate a variable and then use this updated variable for the next iteration in the programs. I thought to use global variable for the common data but i'm unable to make it work. Any help anyone?

답변 (1개)

Edric Ellis
Edric Ellis 2012년 3월 22일
GLOBAL data is never shared between your desktop MATLAB session and the workers running jobs and tasks. However, you might find it somewhat easier to open a MATLABPOOL and then use PARFOR to get your job done. Perhaps something a bit like this:
matlabpool open local 3
done = false;
myFcns = {@myFcn1, @myFcn2, @myFcn3};
overallState = 0;
while ~done
parfor ii = 1:3
result(ii) = feval(myFcns{ii});
end
overallState = overallState + sum(result);
done = (overallState > 42);
end
In other words, you could put your three functions into a cell array of function handles. The PARFOR loop runs these in parallel, and collects the results into 'result', and you can operate on that in your MATLAB session, and then do some more stuff in parallel.
  댓글 수: 1
Sampath reddy
Sampath reddy 2012년 3월 24일
Does parfor function support global variables?

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

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by