How can I run two function in parallel?

조회 수: 2 (최근 30일)
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016년 8월 14일
편집: K M Ibrahim Khalilullah 2016년 8월 16일
I want to run two function in parallel for execution time minimization. Is it possible in matlab. I have two function func1 and func2. The func2 depends on func1. func2 takes 2.5 second and func2 takes 1.5 second for execution. i want to run func1 and func2 simultaneously for reducing execution time. If the two function run simultaneously, then func2 have to wait only for 1s (may be)............
  댓글 수: 5
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016년 8월 15일
Thank you very much. yes func2 requires the completely computed output. But my questions is , if the func1 run some seconds before the running of func2 in parallel. Then may be possible like java...But in matlab is there any way to run two function like that. I don't know that is my idea. Already I reduce the time by converting in C using matlab coder. However, is it possible to implement my idea in matlab?
Pawel Ladosz
Pawel Ladosz 2016년 8월 15일
I don't see how this could happen, unless you can run parts of func2 without the output of func1. In that case you could try and split func2 into two more functions, one of which could be run parallel with func1.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 15일
Use spmd . You can transfer data from one worker to the other using labSend() and labReceive()
  댓글 수: 3
Walter Roberson
Walter Roberson 2016년 8월 15일
Yes, as usual, the local workspace of a function will be destroyed when the function returns.
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016년 8월 16일
편집: K M Ibrahim Khalilullah 2016년 8월 16일
Thank to all for comments. Now I understood that it is not possible to run two dependent functions in parallel. So I have to run in serial..

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by