LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Generic architecture for passing arrays

I searched but couldn't find the answer.  In the RT, if you unbundle anything from a cluster it *always* (it seems) creates a copy.  This takes time but it's no problem for small things.  If, however, you unbundle a large 2D array (say, 25k elements) it can take dozens to hundreds of microseconds (my entire program needs to execute at 400Hz - 2500uS).
 
I've removed my largest array from the cluster and have been passing it around separately (which works and sped things up drastically) but now I have another large array in that cluster.  I could do the same thing but, what if you had 100 large arrays?  Is there a generic way to pass lots of large arrays around in a clean (read, not with 100 wires) and fast way that doesn't involve making a copy every single time you use one of them?  Clusters don't seem to be the answer.
 
Thanks!
 
Lee Jay
0 Kudos
Message 1 of 6
(2,988 Views)
You might try looking through this tutorial and this one. The basic idea that I would recommend would be to create a functional global to store your large arrays. Functional globals, also known as LV2-style globals, are (generally) non-reentrant subVIs that store data in an uninitialized shift register. They then have functions to get or set the values stored in the shift register, as well as any other functions you might want that operate on them.
 
These tutorials have some good recommendations for working with larger arrays. The best tip you might get from this would be to have your functional global only output segments of your large array at a time to minimize the time it takes to allocate that memory, and to lessen your overall memory impact. You should be able to find a good middle ground of having segments that aren't too large vs. having too many segments to operate on.
 
Let us know if you have any questions about these topics. Functional globals are an extremely useful tool that help avoid wire clutter and promote safe, efficient access to data.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 6
(2,981 Views)

Thanks for the tips.  In one of the tutorials you posted, there is this paragraph just after describing the functional global approach:

"Implementing the queue approach is just as easy...This approach is typically faster than the functional global approach. "  My issue is primarily one of speed so should I go this route instead of using the functional global approach?  Also, the queue approach seems somehow more intuitive to me which might make the code more readable to other people.  What do you think?

Lee Jay

0 Kudos
Message 3 of 6
(2,975 Views)
That is true, queues are another very good approach. I think, in general, queues will work very well for your application. The idea is to use a single-element queue to store one piece of data (array) at a time. LabVIEW knows that when you dequeue the element, it doesn't need to make a copy of the data, since it no longer exists in the queue. It simply uses the existing data structure in memory. So everytime you modify the data, you dequeue it modify, then enqueue the modified copy.

I think this will work very well for you. Try it out and let us know the results.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 6
(2,968 Views)
I appreciate your help.  I'll get on it!
 
Lee Jay

Message Edited by Lee_Jay on 07-25-2006 12:30 PM

0 Kudos
Message 5 of 6
(2,968 Views)
Whenever performance is a concern, a wire will always be the most efficient way of transferring data in LabVIEW.  In most cases, the single-element queue will give you the performance that is closest to using a wire.  You'll still need a wire for the queue reference, but if you are going to have several large arrays and don't want a wire for each, you can create an array of queue references and pass this single wire into and out of your sub VIs.
 
Best regards,
David H.
Systems Engineer
National Instruments
0 Kudos
Message 6 of 6
(2,936 Views)