Access variables in parallel computing

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 Comments

You want a background task to count TTL signals from a video camera recording. You want the main task to poke the background task everyone once and while to get the current frame number. More specifically, you don't want the background task to "broadcast" out the current frame to the main task -- the main task will ask for it when it needs it. Is that all correct?
In a moment in time, if the main task asks for the current frame number, by the time the background task receives the request, there current frame number could have changed several times. Or how close to real time does this have to be?
Do you have the Parallel Computing Toolbox? Which version of MATLAB are you running?
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.
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

Sign in to comment.

Answers (2)

The functionality in MATLAB to perform background processing may be of use to you.

2 Comments

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.
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."

Sign in to comment.

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?

Categories

Find more on Parallel Computing Toolbox in Help Center and File Exchange

Asked:

on 4 Apr 2022

Commented:

on 18 Jun 2024

Community Treasure Hunt

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

Start Hunting!