LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto-Indexing For loops by columns of 2-D array

Hi,

My application involves processing of many 2-D arrays. One thread of the processing takes every column of the 2-D array, processes it and produces a 2-D array as output. This output is taken by the next thread which processes every row of the array. I have used auto-indexing to build the array in the first processing. So the array is transposed as auto indexing builds the array row after row. So I had to either include a Index array VI for the second processing or transpose the 2-D output array after the first processing. Both the above seems to take time. is there a wasy to auto-index for loop in terms of columns for 2-D array?? Or is there any other way to speed up the entire process. Speed is very crucial in this application. Kindly reply.

Thanks & Regards,
Aarthi
0 Kudos
Message 1 of 20
(6,615 Views)
If you know the size of the arrays ahead of time you can initialize the array to the proper size, then iterate through doing a replace array subset to populate your rows, columns or whatever order is convenient.

If I remember correctly, Build Array and transpose are "processor intensive" because they must create copies of the data in memory. You wont notice once or twice, but if you performing these functions in a loop you may notice.

Also, auto indexing on a while loop is not as efficient because it is essentially doing a "build array" with each iteration, whereas a For loop can allocate enough for the final array based on the number of iterations.

Its good to keep these in mind when pinching clock cycles....

Hope that helps

Message Edited by tlivingston on 04-25-2006 05:26 PM

0 Kudos
Message 2 of 20
(6,603 Views)

As the previous poster mentioned, it's probably to your advantage to minimize the # of calls to "Transpose 2D Array."  I don't think LabVIEW should need to allocate memory, but it would need to do a bunch of data shuffling.

I'd suggest you try benchmarking a technique that doesn't use auto-indexing.  It sounds like the call to "Transpose 2D Array" is just to enable the option of auto-indexing, right?  Well, another option is not to perform auto-indexing at all, but to use explicit indexing with the loop iteration counter "i".  Depending on the processing you need to do, you can either explicitly slice out a 1 column Array Subset, or you could use 2 nested loops to process individual elements in the order you choose.

I would guess that explicit indexing would be a bit slower than auto-indexing, but it may be faster than the combo of Transpose plus auto-indexing.

-Kevin P.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 20
(6,581 Views)
In contrary to what otheres have said, autoindexing is very efficient, because the LabVIEW knows the final array size from the beginning, it is nowhere near as inefficient as building an array inside a loop. Maybe you should arrange your data so the first loop would do the rows instead?
 
Autoindexing by colum would be much less than autoindexing by row, because to get a colum, LabVIEW needs to extract nonadjacent elements, while autoindexing by row just gets a contiguous subset of the data in memory.
 
Still, you should probably feed your 2D array via a shift register in each loop, then index out out and replace colums or rows as you go.
 
Can you attach a simple example of your code?
0 Kudos
Message 4 of 20
(6,578 Views)
Auto indexing is efficient in a for loop. but not in a while loop.

If using a while loop labview recommends using init array and replace subset.

0 Kudos
Message 5 of 20
(6,572 Views)
Thanks for all your replies. I also remember reading somewhere that auto-indexing is efficient for building arrays that any other technique. I have attached a simple example of my code. The first thread keeps supplying images to queue imageq. The second thread reads imageq, does the processing via columns and writes it in to dispq. The third thread reads the dispq, processes the columns and outputs the image. Now I have a Index array VI in the for-loop of the third thread. I can remove this indexing and enable auto-indexing, but in that case I need to transpose the output of second thread before writing in to dispq. I can go without both these if my output from thread 2 is build column by column instead of row by row. I have to figure out which is the most efficient. Transpose(thread 2) or Index VI(for loop of thread 3) or Replace VI(for loop of thread 2). I think Index VI(for loop of thread 3) is the fastest. If there are any other ways please let me know.

Thanks & Regards,
Aarthi
0 Kudos
Message 6 of 20
(6,558 Views)


@tlivingston wrote:
Auto indexing is efficient in a for loop. but not in a while loop.

True, but the current problem seem to relate to FOR loops, processing array slices of a 2D arra with fixed size.

Thanks, I should have mentioned that. 🙂

0 Kudos
Message 7 of 20
(6,559 Views)
Until I saw the example, I guess i wasnt sure what he was using to build his arrays.

With the FFT in an inner loop like that, I'm wondering if maybe writing a routine in C might get you there faster.

0 Kudos
Message 8 of 20
(6,549 Views)
Hi.. I know that FFT is the most time consuming operation in that application. But it has to there. So I am trying to optimize other parts of the code as much as possible. I have not yet tried C routine for FFT. However one of the LabVIEW engineer's mentioned that the FFT algorithms in Labview are now comparable with C routines in speed.
0 Kudos
Message 9 of 20
(6,547 Views)
Are there any C FFT libraries available in NI website. If yes please let me know.
0 Kudos
Message 10 of 20
(6,539 Views)