LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parallel for loops not working

Solved!
Go to solution

Hi.

I'm learning multi - thread programing. For start I use "parallel for loops" and I was suprised that is not working. One -thread loop work few times faster (depends on settings) than multi - thread. I don't know why and this is my ask to correct my Vi to work properly.

 

Computer Lenovo, G580, Windows 7 home, 64 bits

 

Intel Core i7 3632QM
Ivy Bridge
Specification Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
Package (platform ID) Socket 988B rPGA (0x4)
Number of cores 4
Number of threads 8

LabView 2011.

 

Download All
0 Kudos
Message 1 of 12
(4,119 Views)

Hi,

 

Make the "dluga operacja.vi" Reentrant execution.

 

Since it is not reentrant - all the parallel process has to wait for the other to complete before it shares the "dluga operacja.vi" to the other parallel loop.

 

Hope this helps.

 

Message 2 of 12
(4,095 Views)

Ok. It works, but very strange. 

Thank You very much.

0 Kudos
Message 3 of 12
(4,055 Views)

@gibon wrote:

Ok. It works, but very strange. 

Thank You very much.


It's not very strange if you think about it.  If it's not re-entrant, a new call to the subVI must wait until the last call is complete.

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 4 of 12
(4,047 Views)

@gibon wrote:

Ok. It works, but very strange. 


In what way does it work "strange"? Please explain.

 

In addition to that, make sure you make the benchmarks actually fair. There are quite a few code differences between the two FOR loop (autoindexing, explicit indexing, shift register, etc.).

Your first frame is also quite silly. Why do you run two indentical parallel FOR loop in parallel. Wouldn't one be enough. Simply branch the wire after the loop, right? Also your formula node makes no sense. What is the purpose of "a=inn+1", seems irrelevant since "a" gets redefined two lines later. Also don't put indocators inside the loop. They will skew the results.

0 Kudos
Message 5 of 12
(4,044 Views)

Also note that plain LabVIEw code seems to be about 15% faster than your formula node. Here's a quick rewrite of your code to give you some ideas. (LabVIEW 2011).

Download All
Message 6 of 12
(4,034 Views)

Thank You "billko" and "altenbach"  for answer. Of course You both have right. 

Altenbach - You have right about "linia dluga" - I wanted to make something hard for processor, It have no sense of corurse, this VI's are made to only understend some parallel programing in labview. 

"Why do you run two indentical parallel FOR loop in parallel" -  I made on begin two loops not parallel, later I made some modyfication when I was playnig.

What was "strange" in behavior ?  In "linia dluga" when inside loop is set to "1" the "spreed up" between one and multi -thread is about 3 times, when I set it to "20" this grow to 6,2. That was strange form me, becourse I expected  similar value.

Altenbach - I have one more  question if You can help me - how did You get "High resolution relative seconds.Vi" ? - I mean how did You know that there is this "vi". And thanks a lot for Your modyfications.

0 Kudos
Message 7 of 12
(3,998 Views)

gibon wrote:

What was "strange" in behavior ?  In "linia dluga" when inside loop is set to "1" the "spreed up" between one and multi -thread is about 3 times, when I set it to "20" this grow to 6,2. That was strange form me, becourse I expected  similar value.


A parallel FOR loop has some overhead due to parallelization (splitting up the problem, then reassembling the results, etc.). If the code is very fast, the overhead is proportionally larger. If the subVI takes a long time to finish, the parallelization overhead is insignificant. It is often not worth to parallelize loops that have very simple and fast code.

 


gibon wrote:

Altenbach - I have one more  question if You can help me - how did You get "High resolution relative seconds.Vi" ? - I mean how did You know that there is this "vi". And thanks a lot for Your modyfications.


You can find it in vi.lib\utilities. It is well known.

 

0 Kudos
Message 8 of 12
(3,987 Views)
Solution
Accepted by topic author gibon

@altenbach wrote:

gibon wrote:

What was "strange" in behavior ?  In "linia dluga" when inside loop is set to "1" the "spreed up" between one and multi -thread is about 3 times, when I set it to "20" this grow to 6,2. That was strange form me, becourse I expected  similar value.


A parallel FOR loop has some overhead due to parallelization (splitting up the problem, then reassembling the results, etc.). If the code is very fast, the overhead is proportionally larger. If the subVI takes a long time to finish, the parallelization overhead is insignificant. It is often not worth to parallelize loops that have very simple and fast code.

 


gibon wrote:

Altenbach - I have one more  question if You can help me - how did You get "High resolution relative seconds.Vi" ? - I mean how did You know that there is this "vi". And thanks a lot for Your modyfications.


You can find it in vi.lib\utilities. It is well known.

 


Perhaps not well known enough!  the "Hidden gems" package adds it to your palattes.  It has also been discussed in a comunity nugget


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 12
(3,968 Views)

Hi friends

 

I would like to ask you how to implement a vi that runs 3 loops with different execution time and have a unique stop button.

Attached a example that explain my project problem.

Thanks,

Alexandre.

0 Kudos
Message 10 of 12
(3,718 Views)