LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why built in mean has side effect on parallel loop

Solved!
Go to solution

altenbach wrote:

What LabVIEW version are you using? I checked in both 2013SP1 and 2014SP1 and mean.vi is [reentrant, preallocate clone, inlined]. Seems absolutely safe to parallelize.
The Mean Function, itself, does have the properties you noted (Reentrant, preallocate clone, inline).  However, it is one of those rare NI functions that let you see the Block Diagram, which basically consists of a call to a C function called Mean_head.  This, too, might be reentrant, but might not support the kind of pseudo-simultaneous calls that come with pre-allocated clones.
BS

 

 

 

 

0 Kudos
Message 11 of 14
(899 Views)

@Bob_Schor wrote:
...This, too, might be reentrant, but might not support the kind of pseudo-simultaneous calls that come with pre-allocated clones.

I would be very surprised if NI would inline a VI while the contents are not safe for that.  Maybe we should wait for an official comment from a blue user. 😄

0 Kudos
Message 12 of 14
(886 Views)

@altenbach wrote:

crossrulz wrote:

EDIT: Just looks at the Mean.vi function.  It is NOT reentrant.  Therefore you really could not run many of these in parallel.


What LabVIEW version are you using? I checked in both 2013SP1 and 2014SP1 and mean.vi is [reentrant, preallocate clone, inlined]. Seems absolutely safe to parallelize.


Now I'm confused about what I looked at earlier.  Now I see it as inlined an preallocated clone.  Maybe I was looking at my top level VI when I hit the CTRL+I instead of the Mean.vi...Smiley Frustrated


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
0 Kudos
Message 13 of 14
(880 Views)

This warning is not about whether the VI or DLL is reentrant. The VI is reentrant and the CLN is marked as run in any thread. That leads us to assume it is thread safe.

 

The key here is "may have side effects". LabVIEW defines a side effect as allowing anything other than the wired inputs to influence the output.

 

One example of a side effect is maintaining state between calls. If a VI contains uninitialized shift registers, then parallelizing the loop will likely change the results. LabVIEW does not know whether the DLL inside Mean maintains any state between calls so it warns that there could be a problem.

 

Another example of side effects could be reading from hardware. If you read from a DAQ channel 4 times in a loop, you get 4 readings in sequential time order. If you parallelize the loop, the iterations may not run in order. The 3rd iteration might be the first to claim the hardware so the output array would not be in time order.

0 Kudos
Message 14 of 14
(845 Views)