Access variables in parallel computing

2 次查看(过去 30 天)
Hello everyone,
I have a problem that I'm unsure how to solve:
I have a video camera recording during a task that gives a TTL signal per frame (approx 75 Hz) that I would like to count in the background while the main task is running. However to synchronize the signals I would like MATLAB to access the counter variable at certain points during the task and return the frame number. I have tried using the parallel computing toolbox, however I do not know how to access the counter variable in the background. Is there any way of doing this on one machine or how could this be best achieved?
Thanks in advance for the help,
John
  3 个评论
John Tuff
John Tuff 2022-4-5
Thank you Raymond, what you've described is exactly what I am trying to implement, the counter running in the background and the main task poking the background to get the current status of the counter variable.
The unspecific answer to how close I need it is 'as close as I can get'. How much of a delay would be expected? It doesn't have to be single digit millisecond precise, double digits would be great, low triple digit would be acceptable.
I have the Parallel Computing Toolbox, and I am currently running Version R2021b.
Alice
Alice 2024-6-18
Hi,
A bit late, but I have the same question : I need to access a variable in my main program that is being modified in the background. I can access it sometimes but it will stop updating the variable after some time and give me a constant value when the actual variable is changing, so I think that I'm not going about it the right way.
How did you solve your problem?
Thanks in advance,
Alice

请先登录,再进行评论。

回答(2 个)

Steven Lord
Steven Lord 2022-4-4
The functionality in MATLAB to perform background processing may be of use to you.
  2 个评论
John Tuff
John Tuff 2022-4-4
Thank you Steven for your answer. I have tried to use background processing, however in my case, the background is constantly running, and the foreground would need to access a variable from the background. I have not so far been able to find a solution to this so my question is whether this is possible at all in MATLAB.
Steven Lord
Steven Lord 2022-4-4
Doesn't this paragraph from the documentation page address that?
"Use parfeval with the background pool to run a function in the background. parfeval immediately returns a Future object that represents the function running in the background. To get results from the Future, call fetchOutputs."

请先登录,再进行评论。


John Tuff
John Tuff 2022-4-5
I have tried the following:
This is just my dummy counter to see whether I can access the background.
function x = counter
x = 0;
it = true;
while it == true
x= x+1;
pause(0.5);
%disp(x);
end
In the foreground I start by using parfeval
f= parfeval(backgroundPool,@counter,1)
I would try calling fetchOutputs, but if I do, it waits until the counter function is finished before returning the result.
p = fetchOutputs(f);
for i= 1:10
p = fetchOutputs(f);
disp(p);
disp(i);
pause(0.1);
end
Is there any issue in how I call the functions?

类别

Help CenterFile Exchange 中查找有关 Parallel Computing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by