11-29-2012 12:30 PM
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,
Solved! Go to Solution.
11-29-2012 12:36 PM - edited 11-29-2012 12:39 PM
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?
11-29-2012 12:55 PM - edited 11-29-2012 01:01 PM
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.)
11-29-2012 01:05 PM - edited 11-29-2012 01:59 PM
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?
11-29-2012 01:15 PM
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 )
11-29-2012 01:26 PM - edited 11-29-2012 01:30 PM
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).
11-29-2012 01:32 PM
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 😉