LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While Loops are not working in parallel

Solved!
Go to solution

I have been meaning to connect several Bluetooth devices to my laptop using LabVIEW and communicating with them. Everything is working fine except for the parallelization concept in While Loops. While Loops are supposed to be parallel but what happens in my case is that the execution still works in series. I have made sure that it is not running in parallel by using the highlight execution. Each sub-VI of the sub-VIs that should be working in parallel (since they are put in different parallel while loops) is actually working sequentially. By this, I mean that no more than 1 sub-VI is working at the same time even if in different While Loops. 
Does anyone know why is that?

0 Kudos
Message 1 of 10
(1,849 Views)
Solution
Accepted by Abdelrahman30

Well, you are not posting nor showing your code, so we can only guess. A given subvi can be executed in parallel at different locations of the code only if it's declared as reentrant (see the Execution category in the vi properties). Beware that not all vi's can behave well as reentrant. You may check the help for more details.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 2 of 10
(1,840 Views)
Solution
Accepted by Abdelrahman30

HI Abdelrahman. 

Sounds a bit like you've got some non-reentrant functions within your while loops. where only one instance of the code is allowed to be executed at any time. Have a look at this: Reentrancy: Allowing Simultaneous Calls to the Same SubVI - NI 
If that there is probably some other recourse that the two loops are fighting over. 

Beyond that, I'm not able to assist without seeing some code. (I don't have access to anything newer than 2020 atm) 

Kind regards
LabVIEW Fairy

cRIO Enthusiast
Please mark solutions when appropriate.
Unofficial Forum Rules and Guidelines
Message 3 of 10
(1,834 Views)

Thank you so much for your help. I think that really is the problem. However, what is the difference between "Shared clone reentrant execution" and "Preallocated clone reentrant execution"?

0 Kudos
Message 4 of 10
(1,831 Views)

If I'm not mistaken:
Shared clone, will spawn more clones as needed. 
Preallocated will look at your code and spawn one per call.  

I normally use shared clone, unless I'm on a Real-time system where the occasional Jitter of spawning a clone is not acceptable. 

Kind regards
LabVIEW Fairy

cRIO Enthusiast
Please mark solutions when appropriate.
Unofficial Forum Rules and Guidelines
0 Kudos
Message 5 of 10
(1,822 Views)

@LabVIEWFairy wrote:

If I'm not mistaken:
Shared clone, will spawn more clones as needed. 
Preallocated will look at your code and spawn one per call.  

I normally use shared clone, unless I'm on a Real-time system where the occasional Jitter of spawning a clone is not acceptable. 


Shared Clone will create a new clone as is needed.  It can use less memory as a single clone can be used by multiple instances of the reentrant VI (ex 5 clones could be used for 10 calls if up to 5 are needed at the same time).

 

Preallocated Clone creates a new clone for every call.  This is required if the reentrant needs to maintain state.  It also reduces jitter as the clone pool done not need to be querried and possibly use extra time to spin up another clone.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 10
(1,799 Views)

@crossrulz wrote:

@LabVIEWFairy wrote:

If I'm not mistaken:
Shared clone, will spawn more clones as needed. 
Preallocated will look at your code and spawn one per call.  

I normally use shared clone, unless I'm on a Real-time system where the occasional Jitter of spawning a clone is not acceptable. 


Shared Clone will create a new clone as is needed.  It can use less memory as a single clone can be used by multiple instances of the reentrant VI (ex 5 clones could be used for 10 calls if up to 5 are needed at the same time).

 

Preallocated Clone creates a new clone for every call.  This is required if the reentrant needs to maintain state.  It also reduces jitter as the clone pool done not need to be querried and possibly use extra time to spin up another clone.


So when would you not want to maintain state within your clone?  I'm curious because I want to expand my knowledge in this area.  I've only ever wanted them to act like completely independent VIs.  Thanks!

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 7 of 10
(1,778 Views)

@billko  ha scritto:

@crossrulz wrote:

Shared Clone will create a new clone as is needed.  It can use less memory as a single clone can be used by multiple instances of the reentrant VI (ex 5 clones could be used for 10 calls if up to 5 are needed at the same time).

Preallocated Clone creates a new clone for every call.  This is required if the reentrant needs to maintain state.  It also reduces jitter as the clone pool done not need to be querried and possibly use extra time to spin up another clone.


So when would you not want to maintain state within your clone?  I'm curious because I want to expand my knowledge in this area.  I've only ever wanted them to act like completely independent VIs.  Thanks!


Just an example: number crunching vis with long calculations.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 8 of 10
(1,772 Views)

@billko wrote:
So when would you not want to maintain state within your clone?  I'm curious because I want to expand my knowledge in this area.  I've only ever wanted them to act like completely independent VIs.  Thanks!

There needs to be some distinctions here.  There are reentrant VIs that are called at the very top level VI to just be a separate parallel thread.  These should maintain their own state.  But then there are the reentrant VIs that are "constantly" being called in a loop.  State should not be maintained in those VIs, but maintained by the loop.

 

But that's just my opinion.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 10
(1,755 Views)

@crossrulz wrote:

@billko wrote:
So when would you not want to maintain state within your clone?  I'm curious because I want to expand my knowledge in this area.  I've only ever wanted them to act like completely independent VIs.  Thanks!

There needs to be some distinctions here.  There are reentrant VIs that are called at the very top level VI to just be a separate parallel thread.  These should maintain their own state.  But then there are the reentrant VIs that are "constantly" being called in a loop.  State should not be maintained in those VIs, but maintained by the loop.

 

But that's just my opinion.


This kind of goes along with the post above yours.  I have to consider your responses closely before I say I understand it.  I know you think this is trivial, and it probably is.  It's just new to me, and I appreciate your patience.

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 10 of 10
(1,696 Views)