📄 dispatch.m
字号:
function [vBeta, vErr] = dispatch(vBeta_lim, bPlot, oGeom, k0, sm, tol)
global FontSize server_names server_con
min_beta = vBeta_lim(1);
max_beta = vBeta_lim(2);
colors = {'r.', 'g.', 'k.', 'y.', 'c.', 'm.', 'b.'};
if bPlot
hFig = gcf;
set(hFig, 'doublebuffer', 'on')
end
vWho_full = [];
vBeta_full = [];
vErr_full = [];
vCalc_now = [];
chunk = 2;
num_of_srv = length(server_con);
num_of_first_points = max(chunk*num_of_srv,5);
vLIFO = linspace(min_beta, max_beta, num_of_first_points);
server_betas = cell(num_of_srv, 1);
vData_read_from_srv = ones(1, num_of_srv);
%send geom and k0
for ind = 1:num_of_srv
con = server_con(ind);
pnet_remote(con, 'put', 'oGeom', oGeom);
pnet_remote(con, 'put', 'k0', k0);
end
while 1
if ~isempty(vLIFO)
vStatus = get_status;
free = find(~vStatus & vData_read_from_srv);
if ~isempty(free)
betas = [];
while (length(betas) < chunk) & ~isempty(vLIFO)
[beta, vLIFO] = pop(vLIFO, 1);
betas = [betas beta];
betas = remove_repeats(sort(betas));
duplicates = ismember(betas, vCalc_now);
ind = find(~duplicates);
betas = betas(ind);
end
if isempty(betas)
continue
end
ind = ceil(rand(1)*length(free));
con = server_con(free(ind));
smt_solve_p(betas, con);
vCalc_now = [vCalc_now betas];
server_betas{con+1} = betas;
vData_read_from_srv(free(ind)) = 0;
continue
end
end
if any(~vData_read_from_srv)
vStatus = get_status;
free = find(~vStatus & ~vData_read_from_srv);
while isempty(free)
vStatus = get_status;
free = find(~vStatus & ~vData_read_from_srv);
end
% server returned result
for ind = 1:length(free)
%ind = ceil(rand(1)*length(free));
con = server_con(free(ind));
if strcmp(pnet_remote(con, 'status'), 'ready')
vErr = pnet_remote(con, 'get', 'vErr');
else
continue
end
beta_calculated = server_betas{con+1};
beta_calculated = beta_calculated(:)';
[vBeta_full, s_ind] = sort([vBeta_full beta_calculated]);
vErr_full = [vErr_full vErr];
vErr_full = vErr_full(s_ind);
vWho_full = [vWho_full repmat(con, 1, length(vErr))];
vWho_full = vWho_full(s_ind);
vData_read_from_srv(free(ind)) = 1;
end
if bPlot
figure(hFig)
hold off
plot(vBeta_full, 1./vErr_full,'b')
fixfonts(gca, FontSize);
hold on
for_legend = [];
for ind = 1:num_of_srv
indind = find(vWho_full == ind-1);
plot(vBeta_full(indind), 1./vErr_full(indind), colors{ind})
%percent = num2str(round(length(indind)/length(vBeta_full)*100));
%for_legend = strvcat(for_legend, [server_names(ind,:) ' (' percent '%)']);
end
%if mod(count,10) == 1
% fixfonts(legend(strvcat('Interpolation', for_legend)),round(FontSize/1.5));
%end
axis([min_beta max_beta 0 max(1./vErr_full)*1.2])
drawnow
%pause(0.05)
end
end
if length(vBeta_full) < num_of_first_points
% not enough points for spline yet
continue
end
[vNew_beta, status] = get_new_points(vBeta_full, vErr_full, sm, tol, chunk);
if status == 2
vBeta = vBeta_full;
vErr = vErr_full;
return
end
if status == 1
vLIFO = [];
end
vLIFO = push(vNew_beta, vLIFO);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -