Borrar filtros
Borrar filtros

cprintf not working in parallel situation

3 visualizaciones (últimos 30 días)
Yu Li
Yu Li el 18 de Sept. de 2018
Comentada: Yu Li el 18 de Sept. de 2018
Hi:
I downloaded a color print function in this link:
the function works fantastically, but I found that it can not work in parallel situation.
below are the test code:
parfor i=1:1:100
cprintf('Keywords','this is a test.\n')
end
is there anyway to solve this problem?
Thanks!
Yu

Respuesta aceptada

Edric Ellis
Edric Ellis el 18 de Sept. de 2018
The way cprintf is implemented relies on manipulating the command window in a way that simply cannot be done for a parallel worker. However, you can work around this by sending the stuff to be printed back to the client, and getting it to call cprintf while the parfor loop proceeds. Use a DataQueue to acheive this:
q = parallel.pool.DataQueue;
% Set up 'q' so that it calls 'cprintf' every time it receives a message
afterEach(q, @(args) cprintf(args{:}));
parfor idx = 1:10
% instead of calling 'cprintf' directly, send the arguments
% to 'cprintf' as a cell array
send(q, {'cyan', 'iteration: %d\n', idx});
end

Más respuestas (0)

Categorías

Más información sobre Clusters and Clouds en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by