ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Sum with array functions only

Solved!
Go to solution

Hi,

 

i'm currently struggling to find an array function to generate a running sum array.

My current implementation is working so far. But with bigger arrays (>100000 elements) the throughput is not sufficient.

 

Running sum means:

Each array element is the sum of the previous elements + the value of the according Input-array-element.

INPUT Array:

[100, 10, 95, 95, 5,5,100]

OUTPUT Array:

[100,110,205,300,305,310,410]

 

 

Does anybody know an array/matrix function to speed up this operation? 

If possible without any loops.

 

 

0 Kudos
Message 1 of 17
(7,187 Views)

Hi Daniel,

 

adding up 100k array elements takes ~1ms on my PC:

check.png

Using HighResolutionRelativeSeconds it just reports ~400µs for this routine.

With 1M elements it reports ~4ms, so this scales linearly with number of elements…

 

How much do you want to speed this up?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(7,161 Views)

As fast as possible. Smiley Wink

Down to a few us would be a big advantage.

But in my opinion this is only possible by using array functions.

 

So the question is: 

   Exists an array or matrix function which is doing this operation?

0 Kudos
Message 3 of 17
(7,108 Views)

DaIn wrote:

But in my opinion this is only possible by using array functions.


Based on what evidence?

 

The autoindexing FOR loop is extremely efficient. What makes you think otherwise?

0 Kudos
Message 4 of 17
(7,095 Views)

Using array functions instead of for/while loops was in the past in the most cases a good tool to speed up such operations.

 

This operation is implemented in the SW part of a high-throughput FPGA application.

Maybe using an auto-indexing FOR loop is the best and fastest solution.

But I want to be sure that I'm using the most efficient implementation.

0 Kudos
Message 5 of 17
(7,076 Views)

Hi Daln,

 

ohh wait: we talk about LabVIEW on FPGA now? Why didn't you mention it in the first place?

 

- LV-FPGA can use arrays, BUT usually insists on fixed-length arrays…

- LV-FPGA needs a lot of space to handle big arrays, so you need some streamlining of smaller chunks anyway…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 17
(7,073 Views)

No no....

This function is implemented in the SOFTWARE PART of an FPGA application.

So the FPGA is generating the data. This data is streamed to the Host-vi which is running on a PC.

And this "Running sum" operation is implemented in one of the Sub-vis on the PC.

 

No FPGA solution needed! 

 

0 Kudos
Message 7 of 17
(7,068 Views)

DaIn wrote:

Down to a few us would be a big advantage.


Do the math!

 

To add 100000 elements in a microsecond, an single addition would have to take 10ps.

 

Even if the CPU could do an addition in a single clock cycle, you still would need a 100GHz processor. Not realistic!

0 Kudos
Message 8 of 17
(7,067 Views)

From that point of view: You are correct.

 

Like stated above: 

  I only wanted to be sure, that there is no faster way to do this operation in Labview.

  This is 100% fine for me if it is the fastest way.

 

0 Kudos
Message 9 of 17
(7,063 Views)

For a running sum, especially on a large array you'll only need to keep the previous sum and add the new number, no need to recalculate the previous values that'll be constant.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 17
(7,046 Views)