10-19-2023 05:20 AM
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?
Solved! Go to Solution.
10-19-2023 05:45 AM
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.
10-19-2023 05:48 AM
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)
10-19-2023 05:50 AM
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"?
10-19-2023 05:54 AM
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.
10-19-2023 06:30 AM - edited 10-19-2023 06:33 AM
@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.
10-19-2023 07:13 AM
@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!
10-19-2023 07:20 AM
@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.
10-19-2023 07:58 AM
@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.
10-19-2023 11:35 AM
@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.