LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get parallel while loops to run as separate threads

Hi GUys,

 

I was wondering if there is a way to make better use of the computer processor by multiple threads? Example, if there are two subvi's 1 and 2 running in parallel or just two parallel loops in main, can we get them to run as separate threads? It should appear in the task manager of Windows as a separate processing that is running. LabVIEW.exe is just runs as one thread right? making it slower? Please help me out. THanks!

 

VeeJay

I may not be perfect, but I'm all I got!
0 Kudos
Message 1 of 4
(6,816 Views)

LabVIEW will automatically run the code in separate threads. It is very good about running things in parallel on multiple threads for you. You don't really need to do anything special to make this happen. If you have two parallel loops LabVIEW will run them on separate threads. In addition, it will use all of the CPU cores that you have.



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
(6,808 Views)

Thank you mark!I have 2 subvi's one running at 100ms and the other at 250ms. The one with 250ms is used to count pulses from an encoder to obtain frequency and then speed. What I see is that when I run the program and switch between tabs on my front panel, I see a spike in the frequency value. It is physically non existent but LabVIEW reports it on the graph. This is true when I switch tabs and look at another program that is running. Basically, LabVIEW.exe uses 99% of the system resource. Now, does this mean I need a better computer to run LabVIEW 2009 or should some tweak in the program help me achieve better performance without lags on the screen while switching. Thanks!

 

VJ

I may not be perfect, but I'm all I got!
0 Kudos
Message 3 of 4
(6,795 Views)

@VeeJay wrote:

 LabVIEW.exe is just runs as one thread right?

 


No, not right. LabVIEW.exe is multithreaded (you can enable in Task Manager column which will show number of threads).

 

In general, if you have multiple while loops, they will be executed in different threads. Just create simple VI with two empty while loops without any delays inside, and you will see that both cores occupied (if you have Dual Core CPU).

 

Remember, that UI thread is single. It means, if you have VI with "User Interface" preferred execution system or DLL calls which are not thread safe, or property nodes, then such cycles will be executed in UI thread or will be continously switched between threads - therefore performance penalties may occur.

 

AFAIK by default for each execution system 4 threads reserved (can be increased up to 😎

 

Andrey.

 

0 Kudos
Message 4 of 4
(6,792 Views)