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

5 visualizzazioni (ultimi 30 giorni)
DhanaLakshmiR il 20 Mar 2018
Modificato: William Smith il 26 Mar 2018
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
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.
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(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!!
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Jason Ross il 20 Mar 2018
Modificato: Jason Ross il 20 Mar 2018
You could look at using a DataQueue. There is an example of using one here.
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

William Smith il 26 Mar 2018
Modificato: William Smith il 26 Mar 2018
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);
##### 0 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.5036407,"math_prob":0.6176042,"size":2687,"snap":"2023-40-2023-50","text_gpt3_token_len":816,"char_repetition_ratio":0.1002609,"word_repetition_ratio":0.09768637,"special_character_ratio":0.32005954,"punctuation_ratio":0.20623916,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9826058,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-10-05T01:32:56Z\",\"WARC-Record-ID\":\"<urn:uuid:e00e928f-b84b-47a4-ac80-1db2b84de7e2>\",\"Content-Length\":\"135171\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:497899c2-e2ce-4e88-a164-f749277b9f78>\",\"WARC-Concurrent-To\":\"<urn:uuid:4bf1d94e-73af-4791-bc0f-6b83fc27abdf>\",\"WARC-IP-Address\":\"23.34.160.82\",\"WARC-Target-URI\":\"https://it.mathworks.com/matlabcentral/answers/389396-why-the-data-in-the-workers-cannot-be-plotted-in-graph-in-pct\",\"WARC-Payload-Digest\":\"sha1:GENJWGH6OOX5HAWB5KOWDELKTBSHHKZJ\",\"WARC-Block-Digest\":\"sha1:LGCNGMZXSZRU52DH53LUIHLLGL3KG66R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233511717.69_warc_CC-MAIN-20231005012006-20231005042006-00400.warc.gz\"}"}