LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Subroutine Priority

Can we say that threads are like work benches, processors are like people, and VIs are like tasks?  If we have more work benches than people, people will be going around all work benches to work on tasks assigned to each specific bench.  If you have 3 work benches and 2 people, there would always be one work bench unoccupied.  If you have an equal number of work benches and people, There is always one person on a bench, but the people may switch benches.  

 

For subroutine priority VI (task), it would be dedicated to one work bench (cannot be switch to another work bench), but different people (processors) maybe working on that bench at different time instance.  

 

If I have a task assigned to a work bench, would the task be switch to another work bench?  Would a vi change thread?  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 11 of 16
(1,481 Views)

What do you mean by execution system?  Where can I read more about that 1 thread per processor per execution system out of the box configuration?  

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 12 of 16
(1,481 Views)

Suggested reading:

http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/vi_execution_speed/#SubVI_Overhead

 

I like subroutine priority because it disables the FP controls and indicators allowing me to tweak and benchmark without closing and reopenning a bunch of VIs. 

 

If I did not use LV9 so much I would probably inline more than use subroutine priority, but they are mostly interchangeable.  Either they both would help or hurt, usually one is not significantly better than the other.  

 

If it is in a loop, think subroutine; if it has a loop think again. 

Message 13 of 16
(1,470 Views)

Jeff, Altenbach, thanks for the link about floating point calculation. I should have paid more attention to Jeff's emphasis on meaningful.

 

Jyang72211: Your analogy doesn't quite work.

Only one processor works on a single thread at a time - that is, a thread gets assigned to a processor when that thread is running. The operating system can halt a thread and swap it to another processor, but the thread is never on two processors simultaneously.

 

A normal (non-subroutine VI) gets broken up into "clumps" during compilation. When it runs, the scheduler grabs a clump and hands it off to the next available thread in that execution system. Since an execution system has multiple threads, different parts of the VI could execute in different threads, possibly on different processors, and could even execute in parallel.

 

A subroutine VI executes as a single clump. This also means that a subroutine won't really execute parallel tasks in parallel - they'll execute in a single thread on a single processor. It might look like two parts execute in parallel if instructions for parallel tasks gets interleaved during compilation, but they won't actually execute concurrently the way they could in a non-subroutine. This is why you can't put a parallelized For Loop in a subroutine. Another example of a single thread in LabVIEW is a timed loop, "any code enclosed within the timed loop executes in a single thread." (Don't ask me why parallelized for loops are allowed in timed loops; I assume they just don't execute in parallel but haven't benchmarked it.)

 

See the help for execution subsystems. Each execution subsystem (except the User Interface) is a separate pool of threads. By assigning VIs to separate execution subsystems, you can prevent one group of VIs from monopolizing all available threads. For example, say you have a bunch of loops that all communicate with slow external devices. Each communication might be a separate thread, which could block while waiting for the device to respond. If all your code is in the same execution subsystem, this could prevent anything else from running. By limiting those communications to a separate execution subsystem, you partition that communication so it doesn't interfere with the rest of your code. That said, most of the time you don't have this situation, and as noted in one of the links in this thread you should leave VIs set to "Same as caller" unless you know that they should execute elsewhere. Often you'll assign separate execution subsystems to only a few long-running, almost top-level VIs.

Message 14 of 16
(1,461 Views)

@JÞB wrote:

Thanks for cleaning up that misstatement confussing threads and processors.  To clarify the relationship.  One Thread per Processor Per Execution system is the out of the box LabVIEW configuration.  It can be changed but that is another box of worms entirely.


I seem to remember that the one thread per processor (core) per execution system is not really correct. LabVIEW has changed that default over the time, slowly increasing it from I believe 2 threads in the beginning to currently 8, although I somehow remember that there might be even some heuristics nowadays depending on the number of cores that are available. Allocating 8 threads per core and execution system on a hyperthreaded 16 core system might be a little bit overkill.

 

Rolf Kalbermatter
My Blog
Message 15 of 16
(1,445 Views)

One little side note regarding terminology for the discussion (since i didn't find the term in the thread up till now):

The process of swapping threads/processes caused by priorities is called preemption.

 

Subroutine execution simply suppresses preemption for this thread. But as Nathand made clear: the disable of preemption refers to the LabVIEW.exe process, not for the whole OS. Nevertheless, disabling preemption due to subroutine priority can mess up all the timing in the application leading to

- thread starvation

- priority inversion

- possibly (not likely) even to dead-locks

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 16 of 16
(1,441 Views)