Why the data in the workers cannot be plotted in graph in PCT?

1 回表示 (過去 30 日間)
DhanaLakshmiR
DhanaLakshmiR 2018 年 3 月 20 日
編集済み: William Smith 2018 年 3 月 26 日
In parpool i have two workers. I cannot use the output data in the workers for plotting the graph. How it can be accessed?
delete(gcp('nocreate'))
parpool(2)
delete(gcp);
parpool('AttachedFiles',{'parallel1.m','parallel2.m'})
poolobj = gcp('nocreate');
spmd
first_run = true;
for i=1:5
if labindex == 1
if first_run
A_parameters = 1;
disp('hello');
first_run = false;
else
A_parameters = labReceive()
end
A_output = parallel1(A_parameters);
else
B_output = parallel2(1);
labSend(B_output, 1);
end
end
end
parallel1.m code
function[str1]= parallel1(y1)
filename = fullfile(tempdir, 'talkk.dat');
% Memory map the file.
m = memmapfile(filename, 'Writable', true, 'Format','double' );
m.Data(1) = 0;
for i=1
y11=y1;
% Set first byte to zero, indicating a message is not yet ready.
a=[250000.1594+i 26000+i 27000+i];
str=a ;
len = length(str);
if (m.Data(1)==0)
% Update the file via the memory map.
m.Data(2:len+1) = str;
m.Data(1)=len;
disp('sending message')
end
str1=str;
% Wait until the first byte is set back to zero,indicating that a response is available.
while (m.Data(1) ~= 0)
pause(.25);
end
end
parallel2.m code
function[output]= parallel2(y)
yy=y;
k=1
% Respond to SEND using memmapfile class.
disp('ANSWER server is awaiting message');
filename = fullfile(tempdir, 'talkk.dat');
% Memory map the file.
m = memmapfile(filename, 'Writable', true, 'Format', 'double');
m.Data(1) = 0;
for i=1:5
% Wait until the first byte is not zero.
while (m.Data(1) == 0)
pause(.25);
end
if (m.Data(1)~=0)
textdat = double(m.Data(2:1+double(m.Data(1))))';
output=textdat+1;
%Display the message.
disp('Received message from SEND:')
disp(textdat)
% Signal to SEND that the response is ready.
m.Data(1) = 0;
k=k+1;
end
Data=1;
end
I want this textdat in the worker to be plotted for the whole iteration or any other way to plotting is also appreciated.Kindly give answers.Thanks in advance!!

回答 (2 件)

Jason Ross
Jason Ross 2018 年 3 月 20 日
編集済み: Jason Ross 2018 年 3 月 20 日
You could look at using a DataQueue. There is an example of using one here.

William Smith
William Smith 2018 年 3 月 26 日
編集済み: William Smith 2018 年 3 月 26 日
I have multiple parfor workers plotting 'invisible' graphs then saving to PNG. Seems to work fine.
Pseudocode:
fig = figure('Position', [ 100 100 1000 500 ], 'Visible', 'off' );
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
plot(ax1, ...);
plot(ax2, ...);
print(fig, imageFilename, '-dpng');
close(fig);

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by