01-02-2012 08:40 AM - edited 01-02-2012 08:46 AM
I have a program which produces two elements array. In normally the program ends in microseconds, however when I organize my program to send the array as a data to DAQ.mx write and the array will be the voltage output from my NI USB-6012 DAQ, my program ens in 40 seconds. How can I make my program faster? Is there any solution?
I have attached the normal program and with DAQ.vis.
01-02-2012 09:11 AM
This appears to be a follow-up to this: http://forums.ni.com/t5/LabVIEW/Odd-Index-Transpozed-Arbitrary-1D-to-2D/m-p/1791130
As for your question: what were you expecting? When you have no hardware, of course the code is going to run that fast. Now that you are performing analog input and output, it's bound to run slower. Your outer loop runs 41 times, and for each iteration your inner loop runs ... 41 times. That's 41 x 41 = 1681. I'm surprised it only takes 40 seconds.
Also, you can simplify your code by using the Ramp Pattern function to generate your array of steps and then simply using Reverse 1D Array for the "odd" indices of your outer loop.
01-02-2012 09:12 AM
Comparisons with floats as loop stop conditions is dangerous, you can easily get infinate loops due to rounding errors. Are you sure that's not what's happening?
Start by using the loop 'i' directly, you can easily recalculate how many loops you'll need to run. Or calculate and use a For loop.
/Y
01-02-2012 09:19 AM
Very good point about the floats. Missed that one, and now I have one less nickel in my retirement fund. Time to go back to work!
Of course, the whole comparison thing would be moot if the OP simply used the Ramp Pattern as I suggested.
01-02-2012 12:13 PM - edited 01-02-2012 12:18 PM
Program 1 runs 5 times and program 2 runs 41 times per loop. the total number of inner iterations is 25 vs. 1681 for a 67x difference.
Program 1 and program 2 have no timing information, thus spin at a undefined rate.
Program 2 does single point hardware IO and also has no timing information. The speed will depend on the hardware.
Running at a hardware dependent rate is not a good idea in general, because the speed will vary with every change in hardware and is not deterministic. You don't even know what occurs first at each iteration: the input or the output.
If speed is important, what you should do is use an improved variation (Yes, use FOR loops and ramps!) of program 1 to generate the final data array, then do a single "Nchan,Nsamp" IO, running input and output synchronized hardware timed off the same clock. This way you can select any acquisition speed up the the maximum supported by your DAQ hardware. It will be fast and at an exactly defined rate as it should be! 😄
Try it!
I am not familiar with your hardware: USB-6012. can you give a link to the product page?
01-02-2012 05:10 PM - edited 01-02-2012 05:17 PM