LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fill array is to slow

hello,

in the attachement there is an example.
in this example i've got an array where i want to insert values at column 4.
the attached vi works, but my array can contain 40000 rows.
this takes minutes for the calculation.

is there a way to make this vi faster?

markus
0 Kudos
Message 1 of 7
(3,159 Views)
Hello Markus,

the slow thing is not the insert array, it's the "build array"...

In your loop you build a new array. It would be much faster, if you would replace array elements instead of inserting. And it would help to insert not one element after the other but to insert a whole row/column.

Hope this helps,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 7
(3,154 Views)
Hello Markus,

I changed your example a little bit. It's may be still slow on big arrays.

Best regards,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(3,148 Views)
thanks for this example.
is there any similar function to delete a column??
0 Kudos
Message 4 of 7
(3,141 Views)
Hi

There's a function "Delete From Array". You can set row and column and the according number of elements to delete.

Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 5 of 7
(3,134 Views)
Insert into array will actually have the same problem as Build array because they both have to reallocate memory for the array because it changes the size of the array. Delete from Array will have the same problem.

For maximun speed and effenciency when working with arrays, you should initialize your entire array, then use 'Replace Array Subset' to put your data into the array. With Replace Arrray Subset, you can replace a single element or and entire row or colunm. This doesn't require any memory reallocation since the array never changes size, elements are just overwritten in place. If you don't know how big your array is going to be, initialize it to something larger than you think you'll need. Then you can watch where you are replacing elements, and if you need to increase the size, use a single 'Insert into Array' to add some space, then go back to using the "Replace".

Ed


Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 6 of 7
(3,118 Views)
Yes for speed purposes, you should initialize an array and index calculate and replace elements in a loop. This looks less elegent than just calculating and building an array but is much faster since you are not reallocating memory and copying the array as much. The downfall is that you will have to preallocate a known amount of memory for the array when initialized. You give up the nice dynamic nature of array processing but will get a speed boost in return. You also sometimes have to allocate large amounts of memory to make sure that you have enough room in your array to store all your points but memory is practically free (for most arrays you still only need a few MB at most). Also make sure you are optimized in your processing algorithms (ie move any calculations which are constant in respect to index outside of the calculation loop). One final trick which is possible on hyperthreaded systems (Newer CPU & LV 7.1+) is to split your array in to two parts and process each half in its own parallel loop. Warning that a non hyperthreaded complient system will take a speed hit (might be significant) since there will be a large amount of context switching added to your overhead. In the near future we will be seeing a greater degree of multithreaded and multi-core CPU becoming mainstream so you can keep this in mind if you are developing longterm applications. (if all else fails you can write the process algorithm in c++ and call the .dll from labview, but I will probably be ousted from the Labview community for suggesting such a 'stupid' fix).

-Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 7 of 7
(3,111 Views)