11-23-2011 12:51 PM
Hi,
I have a multiple class instances (say a, b, c,...) that have the same parent and I want to run the same overridden methods to all instances in parallell.
For example:
a.init() -> a.run() -> a.stop() -> a.run() -> a.stop() ->
b.init() -> b.run() -> b.stop() -> -> ->
c.init() -> -> -> c.run() -> -> c.stop()
...
See attachment for details.
The problems now are:
1. the "run"-method does not return until it receives external trigger
2. all run methods return in a different time
Bullet 1 means that I cannot use autoindexed for loop because in this case b.run() has to wait until a.run() finishes, right? Is there a way to run for loop in parallel?
Bullet 2 means that a one object has to be able to run and stop independently of others.
What is the most elegant solution? The copy-paste solution seen in attachment works for 3 instances but currently there are 10 and more is coming.
Juha
Solved! Go to Solution.
11-23-2011 02:27 PM
You need to make your methods reentrant. Any methods that are shared that will take any significant amount of time to complete should also be reentrant. Very simple methods can easily be shared since they will not result in siginificant delay if called at the same time. Reentrant methods (VIs) will be able to run completely independent of each other and in parallel.
11-23-2011 04:44 PM
Actually, what I wanted to know was "How to add the "P" to for-loop"... Easy, after you ask the right question.
In the attachment, there is a test.vi that has two numeric indicators in an infinite while-loops. If I allow parallelism, both of the numeric are incremented infinitely. If I don't allow parallelism, only the first one is incremented (as it never leaves the infinite while loop).
To solve my original problem, I can make one init-run-stop branch inside an indexed-parallel-for-loop and just make sure that there is the same number of loop instances as there is objects in my object array ( object array is the one autoindexed in for-loop).
Also good point about the reentrant vis. I must add that also.