Execute functions and read input simultaneously in Matlab
1 回表示 (過去 30 日間)
古いコメントを表示
I have an mp3 file which needs to go through different functions (blocks) in series. The input of each block is taken from the output of the previous block. Block C needs the longest time to process (eg. 10s). The problem is, instead of waiting the 10s, I wish to read another frame of mp3 while waiting the block C to finish its process. Any idea on the solution?

0 件のコメント
回答 (2 件)
Walter Roberson
2018 年 11 月 3 日
編集済み: Walter Roberson
2018 年 11 月 25 日
If you have the parallel computing toolbox then you can use spmd.
framesize = 4096;
P = parpool(4);
spmd
if labindex == 1
end
end
spmd
if labindex == 1
afr = dsp.AudioFileReader(Filename, 'SamplesPerFrame', framesize);
while ~isDone(afr)
frame = step(afr);
labSend(frame, 2);
end
labSend([], 2)
release(afr)
elseif labindex == 2
while true
frame = labReceive(1);
if isempty(frame)
labSend([], 3)
break
end
Bres = BlockB(frame);
labSend(Bres, 3);
end
elseif labindex == 3
while true
Bres = labReceive(2);
if isempty(Bres)
labSend([], 4)
break
end
Cres = BlockC(Bres) ;
labSend(Cres, 4)
end
else
while true
Cres = labReceive(3);
if isempty(Cres)
break
end
Dres = BlockD(Cres) ;
end
end
11 件のコメント
Walter Roberson
2019 年 2 月 21 日
No. Job scheduler is only needed if you are using the Distributed Computing Toolbox, which would be for running computing on a cluster. Job schedulers are not required for running only on the resources of the local computer.
Star Rats
2019 年 4 月 10 日
Hi Walter, is your answer above considered as Task parallel (Embarrassingly Parallel) or Data parallel (Fine Grained Parallel) ?
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!