LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to pass large amounts of data to subroutines?

I'm writing a program with a large amount of data, around 900 variables.  What is the best way for me to pass parts of this data to different subroutines?  I have a main loop on a PXI RT Controller that is controlling hydraulic cylinders and the loop needs to be 1ms or better.  How on earth should I pass 900 variables through a loop and keep it at 1ms?  One large cluster??  Several smaller clusters??  Local Variables?  Global Variables??  Help me please!!!
0 Kudos
Message 1 of 25
(6,303 Views)


@zorro349 wrote:
I'm writing a program with a large amount of data, around 900 variables. 

What's a variable??? 😉

How about using a simple 1D array with 900 elements?

0 Kudos
Message 2 of 25
(6,294 Views)
I think we would need a little more detail to make really appropriate suggestions, but in general
the fastest way to pass (large sets of) data is to not pass it but use it where it is.  If you can architect your
application to take advantage of functional globals, you can store the data once and leave it,
then use different cases of your functional global to process as required.  You would have to do some
testing to determine whether the f. global call overhead outweighed moving the data.

Some other options would be to use queues (put the data into a single element queue) and pop
it as required.  This would still entail, however, moving the data.

Another option would be to pass just a reference to the control|indicator holding the data.  Again you
would have to do some testing with your application requirements to determine whether pulling
the data out from a reference was quicker.

There is a nice summary (thanks tst) of some of the different approaches here:
http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=2422#M2422

Some general memory usage tips here:
http://zone.ni.com/reference/en-XX/help/371361B-01/lvconcepts/vi_memory_usage/

Sorry this isn't a 'do it this way' answer but hopefully something in here will be useful.

Matt
Message 3 of 25
(6,292 Views)
Well I'm creating new labview code from C++ code.  In this code they have 900 global variables.  These are of different data types, floats, ints, arrays of floats, bools.  Some subroutines(VIs) use as few as 10 of these variables, and some subs(VIs) use as many as maybe 80 of these variables.  I'm trying to come up with the best, and fastest way to pass this data.
0 Kudos
Message 4 of 25
(6,267 Views)
I would start by categorizing the algorithm functions by time criticality.  Things that must
happen every 1ms are highest, 100 ms things like operator interface are lower, etc.

Once the functions are sorted, then scope the data to the sections where it is needed.  User
input, 100 ms items, can probably be handled any way you like as they will effectively be
'constants' as far as the 1ms items are concerned.  If you can get your data scoping granular
enough you might not even have to pass any significant amounts of data.

The key is really going to be in eliminating as much passing as possible and then eliminate
as much memory re-allocation (memory buffer tool) as possible.  In any event, you should
avoid global and local variables as a start.  LV2 style globals, with careful attention to memory
allocations, may work out ok where you can't 'inline' everything.

I haven't tried to translate another language into LV but have had good results starting
with the old flowchart and modifying from there.  If they have 900 globals I would guess
that the original application's design was a little ad-hoc.  Doesn't sound like a fun task.

Matt
Message 5 of 25
(6,262 Views)

Excellent posts Matt!

I have been playing with the idea of devloping a LV Nugget to talk about this.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 25
(6,234 Views)
I already have my function sorted by time criticality.  I have only the time critical stuff in the RT loop set at 1ms.  But there are like 15 subVI's in that loop.  How do I get the data I need in and out of these subVI's? Obviously can't just wire each peice of data to a node on these VI's.  There are way too many peices of data to do this.  So should I group these peices of data in medium size clusters and wire them into the VI's?
0 Kudos
Message 7 of 25
(6,224 Views)

My suggestion, similar to Altenbach and Matt above, is to use a Functional Global Variable (FGV) and use a 1D array of 900 values to store the data in the FGV. You can retrieve individual data items from the FGV by passing in the index of the desired variable and the FGV returns the value from the array. Instead of passing in an index you could also use a TypeDef'd Enum with all of your variables as element of the Enum, which will allow you to place the Enum constant on the diagram and make selecting variables, as well as reading the diagram, simpler.

My group is developing a LabVIEW component/example code with this functionality that we plan to publish on DevZone in a month or two.

The attached RTF file shows the core piece of this implementation. This VI off course is non-reentrant. The Init case could be changed to allocate the internal 1D array as part of this VI rather than passing it from another VI.

 

 

Message Edited by Christian L on 01-31-2007 12:00 PM

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 8 of 25
(6,221 Views)

HI Christian,

Could you check with Roy F about sharing that with the Champions?

We could offer our feedback before you post it.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 25
(6,209 Views)

 


@Ben wrote:

HI Christian,

Could you check with Roy F about sharing that with the Champions?

We could offer our feedback before you post it.

Ben



Will do. Do the Champions have their own discussion group or how do you communicate?

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 10 of 25
(6,202 Views)