LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel for loop 2D array

Solved!
Go to solution

Hello,

 

I do not have any experience with parallel for loops so I need your help.

Goal: Make some calculation (avg, mean) on the rows (or columns) of a 2D array as fast as possible. The calculations are independent from each other and I would like to get a 1D array with the results.

I have read some posts about parallel for loops, and I would like to find an example to my trivial problem but I can't.

Could you help me, is it possible the enhance the effectiveness of the row-based calculation with parallelism in LabVIEW? and It is, could you post an example how I do that? 

 

Thanks,

 

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 1 of 7
(3,646 Views)

Auto index on the 2D array, do the calculations, then auto index the result on the right border to generate the output array. Then configure the loop for parallelism.

 

To do it on columns, transpose first.

 

Do you have a LabVIEW version that has the parallel for loop?

0 Kudos
Message 2 of 7
(3,645 Views)

Hello,

 

Thank you so much for your reply, 

 

Please take a look at my code, am I doing right?

 

- I set the MEAN.VI execution to reentrant and debugg is not allowed,

but I got this msg in Tools -> Find Parallel... (

This For Loop may or may not be safe to parallelize. Warning(s):
- One or more nodes in the For Loop may have side effects.)

 

Loop.png

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 3 of 7
(3,638 Views)

You are doing way too much already. Leave P unwired. Make sure your "mean" subVI is set to reentrant. Why do you make your own "mean"? Why do you do your own ticker?

 

We canont see from the image how the loop is configured. Make sure you generate at least as many parallel instances as you have CPU cores. What is your LabVIEW version?

0 Kudos
Message 4 of 7
(3,631 Views)

Hello,

 

LV: 2011 Version 11.0 (32-bit)

 

The number in the spin control is the default value, ( equals to the number of logical processors )

Loop.png

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
Download All
0 Kudos
Message 5 of 7
(3,624 Views)
Solution
Accepted by topic author D60

If speed matters, don't write your own "mean". Firstly, there is one already in the statistics palette, but secondly, you should either inline your mean VI or do the calculation explicitely (as shown below). the array size never changes for the duration of the FOR loop, so it seems redundant to get the array size with every iteration. 😉

 

Here's what you could do.

 

 

On my rig, this is significantly faster than using "mean.vi" from the palette. Mean has the (1) subVI overhead, (2) needs to get N with every call, and (3) also does some unneeded error checking.

 

(Sorry, I have 32 processors, so the # of instances is set a bit high. Modify as needed).

Download All
0 Kudos
Message 6 of 7
(3,618 Views)

Dear Altenbach,

 

Thank you for your help and useful advices

I am checking this site: http://www.ni.com/white-paper/9393/en#toc5 it seems very useful regarding this issue.

 

P.S: 32 ?! Oh ... 😉 This should be the perfect Christmas gift for me  😉

---
+++ In God we believe, in Trance we Trust +++
[Hungary]
0 Kudos
Message 7 of 7
(3,611 Views)