LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulating DVR Data - Is this correct?

Solved!
Go to solution

Hi there,

 

I'm new to DVRs, but trying to incorporate them into my current project. My data is in a cluster, and some elements I want to change, while others I just want to use in a calculation or a setting. For the elements that I don't want to change, can I just unbundle them before the in-place-element (IPE) where I modify the elements that need modifying? Or will this create a copy of the entire cluster of data?

 

Also, regarding the swap values primitive, am I using that correctly? I understood that if you swap the old value with the new value, then it will be able to put the new value in the old value's memory space.

 

Thank you for any pointers Smiley Tongue you can give me on this topic!

 

DVR_Change_Data.png

0 Kudos
Message 1 of 22
(4,492 Views)
Message 2 of 22
(4,470 Views)

Why do you want to use a DVR? Why bother with the swap? This looks like an unnecessary attempt at optimization.

 

The multiply operation reuses the top input, so you gain nothing from the swap - the operation is already in-place. Many unbundle-modify-bundle operations will also be automatically handled in-place by the compiler, so an IPE (and DVR) are unnecessary.

Message 3 of 22
(4,440 Views)

The code I attached is just an example, but the actual data is more complex, and I will not delete the DVR until the application closes.

 

Right now I am passing around my data using an FGV. By the end of a test the data has some large arrays, the size of one can be about 2000x20, and I thought it might be more efficient to use DVRs.

 

I am not too familiar with the Swap Values function. Should it only be used when the data being stored does not come from the unbundle node?

 

 

0 Kudos
Message 4 of 22
(4,428 Views)
Solution
Accepted by topic author Gregory

gregoryj wrote:

Right now I am passing around my data using an FGV. By the end of a test the data has some large arrays, the size of one can be about 2000x20, and I thought it might be more efficient to use DVRs.


Are you running into an actual problem, or you just think the DVR will be "more efficient"? A large array takes up the same amount of space whether or not it's wrapped in a DVR. A DVR serializes access to that array, as does an FGV or a single-element queue, and so does a normal wire so long as your subVIs that modify that array always pass the input through to the output.


gregoryj wrote:

I am not too familiar with the Swap Values function. Should it only be used when the data being stored does not come from the unbundle node?


In this case it makes your code worse, unless the compiler optimizes it out. The multiply operation normally operates in-place on the top input, if it can. However, with your Swap Values, now the code needs a copy of the unmodified value as well, so it can swap it - you've forced a copy where none was previously necessary! See the screenshot below showing buffer allocations. The version with the swap requires 4 buffer allocations, the version without requires only 3. Don't clutter your code with unnecessary functions that you don't really understand.

WithWithoutSwapValues.png

 

0 Kudos
Message 5 of 22
(4,415 Views)

I do not have an actual problem, and I don't expect that replacing the FGV with something that operates on the DVR will make my code run faster. I just wanted to get some experience with a new concept so I started building it into a project I've been working on. I've also seen a couple sources like this one, which suggest that DVRs should be used instead of FGV when possible.

0 Kudos
Message 6 of 22
(4,364 Views)

So when do I want to use the swap values function? When I am replacing some data with completely different data? (top case). Otherwise, I don't see much of a point to use the IPE for cluster elements when I could just do a bundle by name (bottom case).

DVR_Change_Data.png

 

Thanks,

 

Gregory

0 Kudos
Message 7 of 22
(4,361 Views)

@Gregory wrote:

So when do I want to use the swap values function?


Very rarely, and mostly when you want to actually swap two values. If you're leaving one output unwired, you probably don't need it.

This function is a relatively recent addition to LabVIEW to improve performance in a few unusual cases, for example I've seen sample code that uses it to implement recursive data structures (such as a linked list) efficiently.


@Gregory wrote:

Otherwise, I don't see much of a point to use the IPE for cluster elements when I could just do a bundle by name (bottom case).


So don't use an IPE?

I only use an IPE on a cluster if I'm going to unbundle, modify, and bundle the same data (often the compiler will do this in-place without an IPE). If you only want to either bundle, or unbundle, but not both, use the appropriate function.

 

On the topic of Swap Values, I've used it once in my code (well,twice, but in the same code), as shown here:

IPE.PNG

Here, the "Swap Values" function makes it possible to select either the Rough or Fine History and run the Tune VI in-place on it.

Message 8 of 22
(4,324 Views)

Thank you for all the info Nathan. I have one question pertaining to the IPE when dealing with clusters. Is the only difference in this code cosmetic?

 

Modify_Cluster.png

0 Kudos
Message 9 of 22
(4,279 Views)

I've been holding my breath waiting for Nathan to answer.  I have my guess but I might be wrong.

 

Regardless, this whitepaper appears relevant to the discussion:

http://www.ni.com/tutorial/11472/en/

 

 

0 Kudos
Message 10 of 22
(4,256 Views)