02-27-2017 02:21 AM
Hallo,
is there a way to increase the execution speed of this vi?
by calculating the Y values in the eqn:
Y=a.*sum((1./b).*exp(-b.*(pi.^2)*D*t./c))
b=(2*n+1).^2
n should be from 0 to 100
D changes from 1E-11 to 1E-9 with 1E-13 increment.
This should be performed 30 successive times in another vi. I would be very thankful for suggestions!
02-27-2017 03:16 AM
Hi
I can't have this vi running but I would suggest to calculate constants outside of loops. e.g. c, a.
Also did you analyzed which loop takes most time?
Regards,
Yves
02-27-2017 04:06 AM
This loop for sure, because D varries from E-11 to E-9 with E-13 increment..
02-27-2017 05:22 AM - edited 02-27-2017 05:22 AM
Try using the actual functions instead of the Mathscript.
02-27-2017 06:48 AM
The outer for loop can also be parallellized, which might generate even more performance (it's not always so, but easy enough to test).
/Y
02-27-2017 11:26 AM
@s.steen wrote:
This should be performed 30 successive times in another vi. I would be very thankful for suggestions!
If this is meant as a subVI, you need to define connectors. If performance matters, you could also inline it.
Yes, if performance matters, stick to plain LabVIEW instead of Mathscript. Tim's code is probably similar to what I would do.
In order to compare code, you also need a robust way to benchmark various versions (see the link in my signature)
All you say is that you want to increase execution speed and this can be done by just buying a faster computer (bad idea! :D). It would be important to mention what the speed requirements actually are. What is the hardware you are using to run this (e.g. some tiny embedded target or some fancy Xeon server?).
02-27-2017 11:47 AM
02-28-2017 05:47 PM
Another way to speed up your program is to not build the output array from the FOR loop. Preallocate the result array and use 'Replace Array Subset' to insert the result element(value) into the result array.
Memory allocation is CPU intensive, and every iteration of the loop is requesting more memory to store each new result element into the output.
You would create an array of 'Nan's' to the outside Left of the FOR loop, and wire that to a shift register.
Regards
Jack H.
02-28-2017 05:56 PM
@MrJackHamilton wrote:
Another way to speed up your program is to not build the output array from the FOR loop. Preallocate the result array and use 'Replace Array Subset' to insert the result element(value) into the result array.
Memory allocation is CPU intensive, and every iteration of the loop is requesting more memory to store each new result element into the output.
Autoindexing output tunnels on FOR loops also preallocate memory since it is known how many iterations will be done.
02-28-2017 06:00 PM
@MrJackHamilton wrote:
Another way to speed up your program is to not build the output array from the FOR loop. Preallocate the result array and use 'Replace Array Subset' to insert the result element(value) into the result array.
Building an array in an auto-indexing output tunnel of a FOR loop is equally efficient because the final array size is known when the loop starts and can be fully allocated at once.
Your suggestion just dramatically complicates the code without any benefit.