LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Store the Data

I have "while loop" where I perform some operations. At the end of each cycle I add the data to the existing array (the way as I do it, you can find on the attached picture. ResultData is 2D array, Current is 1D array). Problem is that if I do not store the data the performance is much better (about 40 times faster).

Is any other way to store the data without sacrificing the speed of work?

(I'm tolking about 1.000.000 rows and ~10 columns points in 2D array as a result after all operrations).
0 Kudos
Message 1 of 23
(4,325 Views)
You have two main problems:

(1) The overuse of global variables.
(2) Constant resizing (growing) of arrays.

If you know the final 2D array size, initialize an array with that dimension, then replace rows as you go. At the same time, you should also get rid of all global and local variables, they are not needed and will multiply the use of memory and cpu resource, slowing you down. Global variables should be used sparingly and mostly for UI issues. In a well designed proram, they are rarely needed. Large data arrays don't belong in local or global variables.

Attached is a simple example, and it only takes a few seconds (mostly to calculate the sine function 1000000x in this case).
Message 2 of 23
(4,325 Views)
jonni wrote:
> I have "while loop" where I perform some operations. At the end of
> each cycle I add the data to the existing array (the way as I do it,
> you can find on the attached picture. ResultData is 2D array, Current
> is 1D array). Problem is that if I do not store the data the
> performance is much better (about 40 times faster).
>
> Is any other way to store the data without sacrificing the speed of
> work?

One of the problems is that you have to "iterate" through
all the rows of your data. This isn't necessary. I've
attached an image of a much better implementation that
achieves the same results. This should solve your
performance problem.

--
Michael Aivaliotis
http://mmwis.com
http://forums.lavausergroup.org
http://niwe
ekblog.com


Michael Aivaliotis
VI Shots LLC
0 Kudos
Message 3 of 23
(4,158 Views)
Unfortunately I can not to get rid of global variables. I have simultaneously -independently (but synchronized) running several vis. I can not to see any other ways how to collect information from all of them in one place - only use of global variables. Is any other method available?
0 Kudos
Message 4 of 23
(4,325 Views)
Hi

I agree with the time taken to perform the operation for the vi has been improved.This could be used as one of the solutions.


Best Regards

Atul Wahi
National Instruments
Applications Engineer
www.ni.com
0 Kudos
Message 5 of 23
(4,158 Views)
I'm sure there is a better solution, even if the 2D array is being filled from various modules at various times.
A single copy of your array in memory is already about 80MB (if DBL) and if you are not careful with coding, you might easily generate 10 copies of it and constantly copy the entire thing back and forth between different locations.

Have a look a application note 168: LabVIEW Performance and Memory Management
. Every read operation from a global variable generates a copy of the data!

(Bart Simpson (as a LabVIEW programmer) would probably need to write the following quote 100x on the blackboard: "Do not overuse glo
bal and local variables when working with arrays or strings. Reading a global or local variable causes LabVIEW to generate a copy of the data.
") 🙂

I would store the full array in a "functional global" (LV2 style global), i.e. in a shift register of a subVI. Keep the insert point in another uninitialized shift register. Notice that each "append" call only requires transfer of a single row, the calling VIs thus don't need to read out an extra copy of the full huge array for each append operation. Place a case structure inside the storage VI where you can select various modes (initialize, append, read out, save to disk, get average of column x, etc.) such that most operations remain local to the "functional global" and don't need shuffling of huge arrays back and forth.

How often do you need access to the full array? Another possibility might be to go directly to disk and append each row as a datalog record. It will be easy to later retrieve a few interesting row and memory us
e will be very light.
0 Kudos
Message 6 of 23
(4,325 Views)
Yes it works a bit faster but it is only about 20-50%however i was tolking about 4000% 🙂
0 Kudos
Message 7 of 23
(4,085 Views)
Hi Jonni,

Sticking with the Simpson analogy, "Duh".

Of corse it takes less time to do nothing than something!

Look into using "LV2" style globals (see the link mentioned above).

LV2 style globals can be used just like regular globals BUT you have access to the code they use so you can optimize the performance by using "in-place" techniques.

If you want speed, they are the way to go.

All of the top entries in the "Dictionary Challenge" (see the LabVIEW Zone Challenge) were variations of LV2 globals.

Just trying to help,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 23
(4,085 Views)
I tried several experiments, I run my application 30 seconds:
(Each cycle increases array)

1. No storing the data: 182000 cycles, 6100 commands/sec
2. Shift register (see the picture): 22000 /735
3. my old method using only global variables: 17890 /596

So........ The main amount of time takes the actual adding element to array and NOT the use of global variables 😞

You can see that the difference is 10 times!!!!

Any other suggestions which I can try??
0 Kudos
Message 9 of 23
(4,314 Views)
Try using a preallocated 2D array of fixed size inside the LV2 style global and use replace array subset instead of build array. (Similar to my demo above).
0 Kudos
Message 10 of 23
(4,314 Views)