From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel For Loops inside a Case Structure - one or more threads?

Solved!
Go to solution

I am wondering if I put parallel for loops inside a case structure will the for loops have their own thread or run in the same thread?  

 

I am thinking that it would be one thread, but then I saw this post when looking on the forums to verify.  Alas, I am asking directly.

 

I created the parallel for loops with the purpose of increased performance. (I'm in LV 8.5, so don't have the nifty parallelization option by right-clicking on the for loop).   The parallel loops have the same code in each (I know I need to make the subVIs reentrant).  I wanted to put a case structure around the loops, so that they do not run if there is an error passed to them (I have a modified master/slave structure where the for loops are slaves)  Because the code inside the for loops is 1) dependent on correct data from the master and 2) computationally intensive, I want to skip the for loops' execution if the master has a shutdown command.  Otherwise, errors are likely to be generated in the slaves due to incorrect data from the master or the shutdown does not happen quickly, which may confuse the user.  

 

Let me know if you need more detail.  Thanks!

 

~Kristen

0 Kudos
Message 1 of 4
(2,639 Views)
Solution
Accepted by topic author BlknBlu

Each loop will run on it's own thread and they will run in parallel. The only caveat would be if they are both calling the same subVI and that subVI is not reentrant. For that matter, any shared call that is blocking will result in the two loops not being able to run completely independently.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 4
(2,636 Views)

awesome.

 

do you know why the case structure would not force the loops to run in the same thread?  I guess I am used to thinking about data flow instead of threading...when things are inside the same structure, I think of them as one entity that would have to run in the same thread.  I admit I am not well versed in threading, so your thoughts are greatly appreciated. 

 

Thanks!

 

~Kristen

0 Kudos
Message 3 of 4
(2,630 Views)

LabVIEW is as you say a dataflow language and by definition any node is ready to execute as soon as all of its inputs have been satisfied. LabVIEW will always try to run as much code in parallel. In theory, every operation on a block diagram could be executed on a different thread. The scheduler is constantly looking for nodes that are ready to execute. Naturally, some constructs do group things but the internals can be processed in parallel provided there are no data dependencies.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 4 of 4
(2,623 Views)