How can I run two code blocks in parallel?

3 ビュー (過去 30 日間)
Brendan
Brendan 2013 年 9 月 24 日
I have a few lines of code that I need to run at 200hz (publishing data). I have other code that currently only runs at <100hz, and I doubt I can optimise it far enough to run at 200hz. The data published in the first block of code is generated by the second, but so long as it is publishing at 200hz it won't matter if it is only actually sending new data on every second publish.
I tried parfor, but this doesn't seem like the right solution - as far as I can gather, it runs iterations of the same parfor loop in parallel, whereas I want to run two different blocks of code in parallel (publishing and calculating).
I have access to all toolboxes (academic licence).
Appreciate any help :)
  1 件のコメント
Brendan
Brendan 2013 年 9 月 24 日
Thanks for the responses, spmd looks like what I'll need. I'll implement it tomorrow and let you know how it goes.

サインインしてコメントする。

回答 (2 件)

Ken Atwell
Ken Atwell 2013 年 9 月 24 日
Would batch work for you?

Edric Ellis
Edric Ellis 2013 年 9 月 24 日
An alternative to BATCH might be SPMD. You could do something like this:
spmd(2)
if labindex == 1
% do first thing
else
% do the other thing
end
end
Inside an SPMD block you can also use the labSend family of functions to exchange data if necessary.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by