Saturday, September 15, 2007

New Type of Reentrant VIs


In LabVIEW 8.5, there's a new option for reentrant VIs.

In the VI Properties dialog, on the Execution page, there is a checkbox for Reentrant execution. The "Preallocate clone for each instance" option is the same behavior that reentrant VIs had in previous versions of LabVIEW.

But the "Share clones between instances" option is new. This setting can help you use less memory, but only for reentrant VIs that do not maintain state between calls. Below is information from the feature specification that explains in greater detail.

The main consideration when determining how to set this option is whether the VI remembers some value from one call that must be the same for the next call from the same diagram location. The most common case of this is uninitialized shift registers but it can also be done through local variables, control properties or methods, or the First Call? function. Calling a subVI with this requirement can also cause all reentrant callers to have the requirement.

If the VI does not require state to be maintained, here are the other considerations for deciding how to set this option.
  • Memory usage
    • Preallocate clone for each instance - Clones allocated for every call even if none ever happen at the same time.
    • Share clones between instances - Clones allocated only for the maximum number of calls that happen at the same time.
  • Execution speed
    • Preallocate clone for each instance - SubVI call overhead is constant.
    • Share clones between instances - SubVI call overhead is slightly increased in all calls by the need to retrieve a clone from the cache. In some cases it can be more affected by the need to wait for a new clone to be created or another call to complete, whichever happens first.
  • Debugging ease
    • Preallocate clone for each instance - Breakpoints and probes can be created in a specific clone before the VI is ever executed.
    • Share clones between instances - Any breakpoints or probes in a clone will only affect calls that happen to use that clone. Best practice is to set breakpoints in the original which will be set in all clones or step into the call so the correct clone is debugged.
The behavior of strict VI references is not changed by this setting. Each strict VI reference allocates its own dedicated clone. This leaves the user's code in direct control of how many clones are created and when they are used.

Since the purpose of subroutine execution priority is to reduce execution overhead, reentrant subroutines are always preallocated.

I have also created a short video to illustrate the differences between normal, preallocated reentrant, and shared reentrant subVI execution. The video is posted on YouTube and as a Quicktime movie on my server.

Labels:

Wednesday, September 05, 2007

Create Accessor Dialog and Choose Implementation Dialog


I demo two more new LabVIEW 8.5 features in today's video.

The Create Accessor dialog expedites creating VIs that read or write class data members.

The Choose Implementation dialog helps you navigate from a dynamic subVI call to the implementation you want to see.

I find both of these features to be huge time-savers when working with LabVIEW classes.

Labels: ,