LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

In place element structure - Please explain

Hey guys,

 

I understand how in place elements are good for DVRs, but I would like more information on when to use it. More specifically, on how to know when to use it. From this link (https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/in_place_element/) its explained that it has the potential to stop copying data when not needed. However when I run the "Show buffer allocations" tool from within Labview, I cant seem to see how the example works. Its hard to see so I have circled the black spots which indicate an allocated memory buffer, but I cant see how using the IPES is any better? Maybe I have done something wrong. Please see image below (copied straight from the example). Is the only difference the missing allocation on the increment? I am assuming there should be one on the integer on the top pic too, but it isnt appearing and I dont know why.

 

Thanks heaps

 

inplaceelement.JPG

0 Kudos
Message 1 of 12
(1,850 Views)

You want to use it when you loop with high speed on that operation.

If you just do the operation 1 time , it's useless.

If you use the operation 100 times, it's useless.

From 1000 onwards it will speed up your software execution. In your case specifically, expecially if the array is big (from 1000k elements onwards)

0 Kudos
Message 2 of 12
(1,842 Views)

(the above answer makes absolutely no sense).

 


@Muri777 wrote:

...its explained that it has the potential to stop copying data when not needed. However when I run the "Show buffer allocations" tool from within Labview,


The IPES has fewer primitives, fewer wires, and is easier to read. That's about it in terms of "advantage", but these are desirable features! First of all, both code examples are basically identical. The compiler is smart enough to ignore the array wire branch and "replace array subset" operates in place too. The compiler is smart enough to create equally efficient code for both cases. While there is a buffer allocation for the scalar, it's nothing compared to the array and that tiny allocation will be re-used for all future iterations, so it is basically free.

 

I agree they probably should come up with a better example.

0 Kudos
Message 3 of 12
(1,829 Views)

@altenbach wrote:

First of all, both code examples are basically identical. The compiler is smart enough to ignore the array wire branch and "replace array subset" operates in place too. The compiler is smart enough to create equally efficient code for both cases.


It is usually pointed at the Unbundle By Name - Bundle By Name combination, but what we have here is the "magic pattern", which NI figured out about 2 years after the In Place Element Structure was released.

 

I also prefer using the In Place Element Structure because it seems cleaner.  The compiler doesn't care any more.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 12
(1,785 Views)

@crossrulz wrote:

@altenbach wrote:

First of all, both code examples are basically identical. The compiler is smart enough to ignore the array wire branch and "replace array subset" operates in place too. The compiler is smart enough to create equally efficient code for both cases.


It is usually pointed at the Unbundle By Name - Bundle By Name combination, but what we have here is the "magic pattern", which NI figured out about 2 years after the In Place Element Structure was released.

 

I also prefer using the In Place Element Structure because it seems cleaner.  The compiler doesn't care any more.


I've never considered this seriously until just a couple of weeks ago, I saw someone who used them just about everywhere, and I said, "Now how nice and organized that looks!" and I think this is going to become part of my coding practices.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 12
(1,778 Views)

So besides it being cleaner to look at, I shoudlnt try using them?

 

I dont have arrays that have 100k elements, but I do have software that runs at 20ms on RT and 1ms on FPGA. Are there any other advantages? 

 

Thanks heaps

0 Kudos
Message 6 of 12
(1,721 Views)

The question could be also turned around: Should you NOT use it and the answer to that is actually no!

Should you use it? Yes why not but if you don't you won't generally have any problem since the LabVIEW compiler is usually smart enough to recognize this pattern and generate equivalent code even if you don't use the IPE.

 

But!!!! When you do not use the IPE, you could accidentally add extra code to the diagram that prevents the compiler to do this optimization. With the IPE you will generally not be able to add such code without causing bad wires, so it is in fact more safe.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 12
(1,714 Views)

I had a (edge) case that was less favorable using the IPE structure compared to without. If you want to optimize performance it might be useful to check both solutions.

0 Kudos
Message 8 of 12
(1,687 Views)

@RamonG wrote:

I had a (edge) case that was less favorable using the IPE structure compared to without. If you want to optimize performance it might be useful to check both solutions.


That's not an edge case, but incorrect usage. First of all, prepending elements to an existing array is significantly less efficient than appending. By definition changing the size of arrays cannot be done "in place" anyway. Once you have more information about the problem, I am sure your "algorithm" could be significantly more optimized. Any code that contains a "request deallocation" is highly suspicious anyway. in 99% of cases, it makes things worse.

0 Kudos
Message 9 of 12
(1,671 Views)

@altenbach wrote:

@RamonG wrote:

I had a (edge) case that was less favorable using the IPE structure compared to without. If you want to optimize performance it might be useful to check both solutions.


That's not an edge case, but incorrect usage. First of all, prepending elements to an existing array is significantly less efficient than appending. By definition changing the size of arrays cannot be done "in place" anyway. Once you have more information about the problem, I am sure your "algorithm" could be significantly more optimized. Any code that contains a "request deallocation" is highly suspicious anyway. in 99% of cases, it makes things worse.


I know it was the wrong approach, it's one of those things you know you need to revisit but don't because there's never time to do so. My point was to warn against using primitives that you don't fully understand, just like I did.

0 Kudos
Message 10 of 12
(1,662 Views)