Parallel computing problem

2 visualizaciones (últimos 30 días)
Sampath reddy
Sampath reddy el 22 de Mzo. de 2012
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?

Respuestas (1)

Edric Ellis
Edric Ellis el 22 de Mzo. de 2012
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 comentario
Sampath reddy
Sampath reddy el 24 de Mzo. de 2012
Does parfor function support global variables?

Iniciar sesión para comentar.

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by