How to execute parallel functions ?

조회 수: 9 (최근 30일)
Paul-Henri Michel
Paul-Henri Michel 2013년 4월 22일
Hi everyones,
I have a three buffer system and It takes 3 steps : - I need to collect data from a .txt file - I need to filter these data - I need to plot the filtered data
I want to do these three steps simultaneously ! (even if I have a delay between current data and plotted data) Should I use a parfor loop, matlabpool or multi-thread programming ?
Thanks a lot !
  댓글 수: 1
Paul-Henri Michel
Paul-Henri Michel 2013년 4월 22일
Notice I need to have all the computed data on the same workspace, and I have to use these at each moment.

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

채택된 답변

Friedrich
Friedrich 2013년 4월 24일
편집: Friedrich 2013년 4월 24일
Hi,
look at createTask and createJob. You create a Task for each file, let the worker process is and pass the data back to MATLAB. In MATLAB you get that data and plot it and restart the process:
c = parcluster; %or maybe c = findResource('scheduler','Configuration','local');
job = createJob(c);
for i=1:3
createTask(job,@rand,1,{i});
%create a function handle to the function you use to process the file, pass in the filename as argument to the function to be able to use the same function for all files
end
submit(job);
wait(job);
results = job.fetchOutputs %maybe you need getAllOutputArguments depends on the version you are using
job.delete
Or use SPMD (this should give a better peformance as CreateJob/CreateTask because te workers need to be started only once)
matlabpool open 3
result = cell(3,1);
spmd
switch labindex
case 1
result{1} = rand(1); %process file 1
case 2
result{2} = rand(2); %process file 2
case 3
result{3} = rand(3); %process file 3
end
end
%each worker holds its own result because result is a Composite object
result
result{:}

추가 답변 (4개)

Paul-Henri Michel
Paul-Henri Michel 2013년 4월 23일
No answers ?
Thanks !
  댓글 수: 11
Paul-Henri Michel
Paul-Henri Michel 2013년 4월 23일
편집: Paul-Henri Michel 2013년 4월 23일
No I mean one Matlab for computing and one Matlab for plotting. Once the first Matlab has finished to filter data, I send the data to the second Matlab, which display these on a "hold on" figure and I restart the operation !
But maybe the UDP protocol is too slow to do this, because my file data contain more than 4 000 characters.
Friedrich
Friedrich 2013년 4월 23일
Plotting doesnt take much time. Using a MATLAB for Plotting only seems a bit too much. I would do all that in one MATLAB. You can use PCT to read in the 3files and post process it. You then use these results and plot it and then start over again. This can run in 1 MATLAB.
You use the second MATLAB for your own.

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


Paul-Henri Michel
Paul-Henri Michel 2013년 4월 23일
Ok, now I don't consider plotting data, I just want read data and filter data (other data obviously) simultaneously. In fact, I need two workers on the same workspace ?
Should I use parfor loop, matlabpool ?
Thanks !
  댓글 수: 2
Friedrich
Friedrich 2013년 4월 23일
Why do you need the same workspace? You can put the data together later on.
Paul-Henri Michel
Paul-Henri Michel 2013년 4월 23일
What do you mean by later ? On each end of cycle (end of each worker) I need data and I restart a new loop.

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


Paul-Henri Michel
Paul-Henri Michel 2013년 4월 23일
No answers for : how to give work to two workers on the same Matlab session ?
Thanks !

Paul-Henri Michel
Paul-Henri Michel 2013년 4월 24일
Up :)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by