LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreading With Structures

Hello all. Is it possible to multithread subVIs withing structures
(i.e. loops and case).

I've written a subVI that does three things: Gets the current time,
generates a random number, and then writes both values to a text file.
It continues doing this for a random length of time. The subVI has the
"Reentrant Execution" option selected. My purpose for this subVI is to
understand how multithreading works in LabVIEW.

I created two main VIs. The first one has two independant calls to the
subVI. When comparing the data generated by both subVI calls, the time
stamp is exactly the same and the random number is different. This, to
me, indicates that it is multithreading correctly.

However, in the other VI, I have a for str
ucture that runs twice, each
time calling the subVI. When looking at the data results this time,
file 1 has time stamps from time A to time B. File 2 has timestamps
from time B to time C. In other words, the subVIs are executing one
after the other and not at the same time.

From this evidence, it appears to me that there seems to be a difficulty
in multithreading withing structures. Is there anyway around this
problem?

Scott

P.S. Could anybody point me in the right direction to write a COM
object that can handle arrays from LabVIEW?
0 Kudos
Message 1 of 3
(2,891 Views)
Hi Scott,
I recomend you to see this file in NI site.
http://zone.ni.com/devzone/devzone.nsf/webcategories/8ABEC12D4C0AA4A3862567AC00583899?opendocument

Mike

Scott Royer III wrote:

> Hello all. Is it possible to multithread subVIs withing structures
> (i.e. loops and case).
>
> I've written a subVI that does three things: Gets the current time,
> generates a random number, and then writes both values to a text file.
> It continues doing this for a random length of time. The subVI has the
> "Reentrant Execution" option selected. My purpose for this subVI is to
> understand how multithreading works in LabVIEW.
>
> I created two main VIs. The first one has two independant calls to the
> subVI. When comparing the data generated by both subVI calls, the time
>
stamp is exactly the same and the random number is different. This, to
> me, indicates that it is multithreading correctly.
>
> However, in the other VI, I have a for structure that runs twice, each
> time calling the subVI. When looking at the data results this time,
> file 1 has time stamps from time A to time B. File 2 has timestamps
> from time B to time C. In other words, the subVIs are executing one
> after the other and not at the same time.
>
> From this evidence, it appears to me that there seems to be a difficulty
> in multithreading withing structures. Is there anyway around this
> problem?
>
> Scott
>
> P.S. Could anybody point me in the right direction to write a COM
> object that can handle arrays from LabVIEW?
0 Kudos
Message 2 of 3
(2,891 Views)
Scott Royer III wrote in article
<3A64A3B3.D22706CF@hamsoft.com>...
> Hello all. Is it possible to multithread subVIs withing structures
> (i.e. loops and case).
>
> I've written a subVI that does three things: Gets the current time,
> generates a random number, and then writes both values to a text file.
> It continues doing this for a random length of time. The subVI has the
> "Reentrant Execution" option selected. My purpose for this subVI is to
> understand how multithreading works in LabVIEW.
>
> I created two main VIs. The first one has two independant calls to the
> subVI. When comparing the data generated by both subVI calls, the time
> stamp is exactly the same and the random number is different. This, to
> me, indicates that it is multithreading correctly.
>
> However, in the other VI, I have a for structure that runs twice, each
> time calling the subVI. When looking at the data results this time,
> file 1 has time stamps from time A to time B. File 2 has timestamps
> from time B to time C. In other words, the subVIs are executing one
> after the other and not at the same time.
>
> From this evidence, it appears to me that there seems to be a difficulty
> in multithreading withing structures. Is there anyway around this
> problem?

The main thing in LabVIEW you have to watch out is data flow. It
determines how LabVIEW does execute the VIs. In order for execution
of the second VI the structure frame for the previous call has to be
finished
which means every VI and function node inside must have terminated.

If you want to do things in parallel they must be placed beside each other
in
a diagram or data dependency will force them to execute serialized.

Also reentrance for subVIs allows some kind of multithreading but it
doesn't
force it if data dependencies do not allow for it. I say some kind of
multithreading
because it is not the same as using multithreading in LabVIEW on platforms
which support it in the OS. If a VI is reentrant it CAN be called multiple
times
from different locations in parallel. If it is not reentrant LabVIEW will
serialize
calls to subVIs and force the second caller to wait until the subVI returns
control
to the first caller.

Rolf Kalbermatter
CIT Engineering Nederland BV tel: +31 (070) 415 9190
Ohmweg 11A fax: +31 (070) 415 9191
3442 AA Woerden http://www.citeng.com
Netherlands mailto://rolf.kalbermatter@citeng.com
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 3
(2,891 Views)