User input during parallel computing
显示 更早的评论
I have a program that runs in parallel to control a motor. One pool for motor control and one pool for sensing outside influances.
Now I want another pool that can procces user input.
I tried to use the function 'input', but the prompt never showed in the command window and this even blocked the parpool from closing down when the other pools were done. I want to ask a simple Y/N (or 1/0) question to initize close down procedures build in in the program (saving etc.) so a whole GUI is not preffered.
some code to reproduce the problem:
function data = Main
data1.x = []; data2.x = [];
funList = {@fun1,@User};
dataList = {data1,data2};
parpool(2)
spmd
funList{labindex}(dataList{labindex});
end
delete(gcp)
%
function fun1(data1)
disp('fun1 Started')
Stop = 0;
while Stop == 0
x = 'Do Something';
if labProbe(2, 201) == 1
Stop = labReceive(2, 201);
end
pause(3)
end
disp('fun1 Finished')
%
function User(data2)
disp('User Started')
Stop = 0;
while Stop == 0
disp('Ask question')
UserInput = input('Do you want to stop? [1/0], [0]');
if UserInput == 1;
Stop = 1;
labSend(Stop, 1, 201);
end
end
disp('User Finished')
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Parallel Computing Fundamentals 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!