How can I create timer objects which are running in parallel in MATLAB 7.13 (R2011b)?

21 views (last 30 days)
I have written an application that needs to compute certain tasks in different time intervals. I am using two timer objects: T1 fires every 50ms, T2 fires every 250ms to execute a piece of code. Both timers should run independently. However I noticed that the slower timer T2 is blocking the faster timer T1 when it is executed. I am working on a system using a multi-core CPU and I would expect MATLAB to be able to execute both timer objects in parallel taking advantage of the computational cores.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
MATLAB enables certain low-level linear algebra and element-wise operations of its underlying libraries to create multiple computational threads. This may lead to a performance improvement. The degree of improvement on performance depends on the nature of the computation, your machine, and whether or not your operating system can leverage these multiple threads. However MATLAB is currently not a fully-multithreaded application. When you begin execution on a computationally intense file at the Command Prompt you will not immediately regain useful control of the MATLAB command line. For the same reason, the computation of the slower timer T2 (executed every 250ms) might block the execution of the faster timer, as both are living in the same thread. In general users do not have low-level control of threads and MATLAB as there is no threading API provided.
However if you are working with Parallel Computing Toolbox you can run the timer objects in separate tasks, so each timer is processed by a separate MATLAB worker. The attached example paralleltimertest.m is creating two tasks: task 1 creating timer 1 (50ms) and task 2 executing timer 2 (250ms) executing the timerfun.m function.

More Answers (0)

Categories

Find more on MATLAB Parallel Server in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!