取消
显示结果 
搜索替代 
您的意思是: 

parallel for loops not working

已解决!
转到解答

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.

 

下载全部
0 项奖励
1 条消息(共 12 条)
5,501 次查看

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.

 

2 条消息(共 12 条)
5,477 次查看

Ok. It works, but very strange. 

Thank You very much.

0 项奖励
3 条消息(共 12 条)
5,437 次查看

@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 项奖励
4 条消息(共 12 条)
5,429 次查看

@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 项奖励
5 条消息(共 12 条)
5,426 次查看

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).

6 条消息(共 12 条)
5,416 次查看

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 项奖励
7 条消息(共 12 条)
5,380 次查看

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 项奖励
8 条消息(共 12 条)
5,369 次查看
解答
接受人 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 项奖励
9 条消息(共 12 条)
5,350 次查看

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 项奖励
10 条消息(共 12 条)
5,100 次查看