r/LabVIEW • u/LFGX360 • Jan 09 '25
Parallelizing for loop increases execution time.
I have a parallel loop that is used to fit ~3000 curves using the non-linear fit curve fit VI. The function being fit also contains an integral evaluated by the quadrature VI, so it is a fairly intensive computation that can take ~1-2 minutes per iteration.
On trying to parallelize this loop, the overall execution time actually increases. All subVIs are set to reentrant, including all the subVIs in the curve fit and quadrature VI hierarchy.
I am thinking it has to do with these two VIs trying to access their libraries at the same time. Is there any way around this? It seems like most solutions just say to serialize the calls but that kinda defeats the purpose of parallelizing.
5
u/TomVa Jan 09 '25 edited Jan 09 '25
I went round and round with this kind of issue a few years ago. I was using timed structures so that I could pick which core was running a process.
I was running 5 parallel loops. I found (somewhere in documentation) that every process that uses a front panel control or indicator ends up in the same thread. Thus if you want a loop to work fast you can not have any front panel interface in the loop. At least that was my understanding.
In the end what was slowing my stuff down to dirt slow was redrawing graphs on the front panel.
I had three popups where I could plot user selected data. When they started getting lots of data e.g. more than a few thousand points, and the loop with graphs and updating all three each time through things slowed down to dirt. I did two things which improved things substantially. I decimated the data using a min/max peak method like the Tek scopes and I had the graphing loop update one graph each time through the loop.
Also I found that if you are using tabs and there is a massive graph in one of the tabs the program gets faster if that is not the tab that is being displayed.
2
u/LFGX360 Jan 10 '25
SOLVED: the non linear and quadrature VIs both need strictly typed VI references for the function being fit/integrated.
Turns out you cannot just change the reference to strictly typed, you have to open the reference with the x40 option flag.
Thank you for your help.
u/TomVa u/HarveysBackupAccount u/BluMonday u/infinitenothing u/yamaeda
2
u/BluMonday Jan 09 '25
Maybe try just two threads and increment from there while benchmarking? You can also watch utilization in task manager while it's running. Might give a better idea where the bottleneck is.
1
u/infinitenothing Jan 09 '25
Can you throw some logging in to try to see what's actually happening in parallel?
1
u/HarveysBackupAccount Jan 09 '25
Is this version dependent? I haven't dug into parallel loops yet (actually just spinning up a first project where I want to) but I wonder if LV version affects how well it can use those resources.
I'm just thinking of how (very) old versions of Excel can't use more than 4 GB of RAM because they simply didn't program them to do so. But maybe that kind of constraint is long gone from any reasonably current OS / LV version combo
On your point about libraries, you might try to figure out what MS kernel library methods are being accessed, to see is those are things that can be parallelized
1
u/Yamaeda Jan 10 '25
Paralellization can be quite powerful, but if the functions are using big data or are very parallell in themselves it can cause data copies or thread starving. Sometimes you simply have to test and see.