SPMD multiple calls for function

3 visualizzazioni (ultimi 30 giorni)
Avinash Rangarajan
Avinash Rangarajan il 19 Giu 2020
Hi. I am creating two parallel calls using spmd, one will receive data through socket and send the data to other worker using labsend.
after that i expect the system to exit out properly, but the 1st worker is called again and raises an error.
% parpool(2)
% parfevalOnAll(@maxNumCompThreads, 0, 2)
main.m
spmd(2)
labindex
if labindex == 1
init();
else
a = plot_fn();
end
end
% to delete the parpool
figure(1)
plot(a{2});
p = gcp;
delete(p)
init.m
% Testing Asynchronous data communication
function [udp_sock] = init()
udp_sock = udp('127.0.0.1',8000, 'LocalPort', 8000);
try
% Code to be executed goes here.
udp_sock.Status
fopen(udp_sock);
catch
udp_sock.Status
disp('Already open');
end
sampleXMLfile = 'blk_id.xml';
matlab_struct = parseXML(sampleXMLfile);
udp_sock.Status
udp_sock.ReadAsyncMode = 'continuous';
udp_sock.DatagramTerminateMode = 'off';
udp_sock.BytesAvailable
store = corres_data_type(matlab_struct.Children(2).Children(2).Children(2).Attributes(3).Value);
val = 1
mystring = fread(udp_sock, 2, store);
my_new_val = fread(udp_sock, mystring(2), 'char');
labsend(my_new_val, 2);
val = 2
fclose(udp_sock);
end
plot_fn.m
function [data] = plot_fn()
srcWkrIdx = 1
[data] = labReceive(srcWkrIdx);s
%a = data;
end

Risposte (0)

Categorie

Scopri di più su Parallel Computing Fundamentals 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!

Translated by