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.
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.
03-10-2011 02:29 PM
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
Solved! Go to Solution.
03-10-2011 02:44 PM
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.
03-10-2011 02:56 PM
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
03-10-2011 03:04 PM
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.