Execute functions and read input simultaneously in Matlab
Mostrar comentarios más antiguos
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?

Respuestas (2)
Walter Roberson
el 3 de Nov. de 2018
Editada: Walter Roberson
el 25 de Nov. de 2018
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 comentarios
Star
el 6 de Nov. de 2018
Walter Roberson
el 6 de Nov. de 2018
I had the dsp initialization there but moved it and forgot to remove the step.
Star
el 24 de Nov. de 2018
Editada: Walter Roberson
el 25 de Nov. de 2018
Walter Roberson
el 25 de Nov. de 2018
Editada: Walter Roberson
el 25 de Nov. de 2018
labSend(DataToSend, 3)
And to receive it,
labReceive()
Star
el 5 de Dic. de 2018
Walter Roberson
el 5 de Dic. de 2018
what is size() of the item you labSend() ?
Star
el 5 de Dic. de 2018
Walter Roberson
el 5 de Dic. de 2018
you are sending a single row but receive into 4 rows. Are you wanting to copy the same one row to all four rows of the matrix ?
Star
el 21 de Feb. de 2019
Walter Roberson
el 21 de Feb. de 2019
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
el 10 de Abr. de 2019
Hi Walter, is your answer above considered as Task parallel (Embarrassingly Parallel) or Data parallel (Fine Grained Parallel) ?
Star
el 5 de Dic. de 2018
2 comentarios
Walter Roberson
el 5 de Dic. de 2018
What you labSend is indexed by row so you only send one row .
Star
el 6 de Dic. de 2018
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!