LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop Parallelism Optimization

Hello, I am working on a project and in this one I regularly use loops to perform various operations and in particular calculations on elements of tables of variable dimensions.

 

Everything works perfectly but the execution time is too long and I want to improve it. This is where I learned about "For Loop Parallelism".

 

However, after multiple tests I realized that this feature did not always improve the execution time of my loops. (see the attached VI)

(Worth It)

coco82_0-1647967933914.png

coco82_0-1647969057762.png

(Not Worth It)

 

coco82_1-1647967952954.png

coco82_1-1647969084519.png

 

 


Is there a way to know in advance the cases in which the parallelism will be profitable and which it would not be the case?

 

Thanks in advance.

0 Kudos
Message 1 of 11
(1,279 Views)

I think VI Analyzer can help there.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 11
(1,268 Views)

There is a parallelization overhead to split the problem and reassemble the results. Do you really need 5D arrays? Why all these coercion dots? You did not even disable debugging!

 

If the task inside the loop is small, the parallelization overhead dominates, as in your case. Parallelization helps if each iteration requires significant effort.

0 Kudos
Message 3 of 11
(1,261 Views)

Hi coco,

 

despite the other good advices you already got you also should try to use NO LOOPS at all - atleast benchmark such possible solutions:

I agree it most often doesn't make sense to work with 5D arrays.

And you should try to avoid coercion dots on large arrays too - even though there is one in my added code…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(1,237 Views)

In my experience, parallelism is useful only if the content of the loop takes significantly longer to execute than the overhead to manage the parallelism.

For example, signal analysis, accessing multiple instruments are situations which are benefitted from parallelism.

 

As a rule of thumb, if the loop content takes ~5ms or more to execute, you will be benefitted from enabling parallelism.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 5 of 11
(1,223 Views)

@GerdW wrote:

despite the other good advices you already got you also should try to use NO LOOPS at all - atleast benchmark such possible solutions:

 


Ha! I actually played with the same ideas earlier. One blemish is the need to allocate that huge boolean and integer array, but the multiplication can take better advantage of SIMD instructions. (Hard to tell what the compiler does behind the scenes). 

 

In any case, these indicators need to go behind the sequence frames because updating them with these gigantic amounts of data suck CPU from the timing, potentially interfering with reading of the last tick:

 

No, an empty frame should not take 70ms!!!!!

 

altenbach_0-1647979348525.png

 

.

 

 

Message 6 of 11
(1,213 Views)

Thank you for all your answers.

@billko I will look at the VI Analyzer.

@altenbach @GerdW Unfortunately most of the operations I perform need to use 5D arrays and I can't usually not use a loop like in the first attached VI.
I apologize for the coercion dots, I made the VIs in a hurry and I didn't pay attention, but in general I avoid them, I read that it could slow down since it creates a copy of the data.

@santo_13 That was my understanding, but I was just wondering if there was a tool to predict in advance if the parallelism would accelerate. For the moment I test my loops one by one to see if the parallelism speeds up or slows down my system but the idea was to avoid all that.

0 Kudos
Message 7 of 11
(1,168 Views)

Hi coco,

 


@coco82 wrote:

Unfortunately most of the operations I perform need to use 5D arrays and I can't usually not use a loop like in the first attached VI.


Why do you need 5D arrays? (Do you really need them?)

 

In my experience LabVIEW can handle 1D/2D arrays much faster than 3+D arrays. Is there a way to transform your 5D problem into a 1D memory presentation?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(1,159 Views)

@GerdW wrote:

Hi coco,

 


@coco82 wrote:

Unfortunately most of the operations I perform need to use 5D arrays and I can't usually not use a loop like in the first attached VI.


Why do you need 5D arrays? (Do you really need them?)

 

In my experience LabVIEW can handle 1D/2D arrays much faster than 3+D arrays. Is there a way to transform your 5D problem into a 1D memory presentation?


Yes, maybe some timely concatenation instead of autoindexing could help here.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 11
(1,135 Views)

Unfortunately, there is no tool to predict that but with sufficient experience, you might be able to make a good guess. Again, even if there were a tool, the tool would not know anything about the runtime data sizes that might affect the execution time, for example, an FFT operation with just 2 elements vs 1 million elements, this is something the tool cannot forsee.

 

Everything boils down to what your real application is and optimize for that.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 10 of 11
(1,123 Views)