LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to really process 2 identical sub VI in parallel?

Hello all,

I've designed a subVI that handles some data over the serial interface of the PC to talk to a custom device using a home-made DLL. The complete procedure takes around 30s.

I need to use this subVI in a VI to handle data over 2 different serial port in parallel to control 2 devices.

The problem is: I instantiate 2 times the subVI in a main VI. When I enable the highlighting to debug, I see that the first instance is executed then the second, that means that the work is done serially. Procedure time is 60s.

I tried to duplicate the subVI and the DLL (2 different names but same intern behaviour with corresponding DLL) ie subVI1 use DLL1 and subVI2 use DLL2.

With the highlight debug feature I see that both subVI are started at the same time but the procedure takes 60s. It is equivalent to a serially-done work.

Is there a way to "really" do the work in parallel? (The PC is able to run both quickly without doubling the time).

Is there a way to create some real thread that the OS manage and not Labview?


Hope you understood me. Thanks in advance.
Best regards
0 Kudos
Message 1 of 11
(4,025 Views)

Hi Fabrice,

To answer your questions:

1.  Is there a way to "really" do the work in parallel? (The PC is able to run both quickly without doubling the time).

The answer is yes (with hesitation based on definition of real parallel).    Since I don't know which OS you are using, this answer is based on Windows products...   So, let's say yes...

The way to do it is to make the sub-vi re-entrant and you can place the two within your vi.  Their outputs meet at a "Rendez-Vous".  Of course, although you have two of the same sub-vi's in your vi, they are configured differently in order to communicate with the appropriate serial port.  Unfortunately, I do not have LV on my work PC, so I can't walk you through the steps of making it re-entrant (I'll find a past post on this).  However, I seem to remember that it is set within the Properties of the vi (or sub-vi in this case).

 

2.  Is there a way to create some real thread that the OS manage and not Labview?

Well.  That depends on your OS.  Windows is not a true multi-tasking OS.  I would let LV manage it's threads.  You can set priorities for parallel execution and rendez-vous points.  Unless you are running LV on a Unix-based machine (Linux included), then LV is probably the better way to go. 

Hope this helps,
 
JLV
 
Message 2 of 11
(4,010 Views)

Hi Fabrice,

Here is how you make a sub-vi re-entrant:

Select the sub-vi, under "VI Properties", select "Execution" and change the "Normal Priority"  to "Reentrant Execution".

Regards,

JLV

Message 3 of 11
(4,006 Views)

Hi Fabrice,

i want to second JLV's comments right up to a point.

The point is the dll.

The dll must be "thread-safe" for you to be able to run tow instances of it at the same time. Not all dll are thread-safe.

If the dll is not thread-safe (LV plays it safe and assumes they are not) the the dll call will run in the UI thread which is by definition single threaded.

If you can verify that the dll is thread-safe, then the dll call can be configured to NOT run in the UI thread. The difference in these type of dll calls can easily be distinguished by looking at the color of the dll call node. Orange is UI thread. Yellow is thread-safe.

I suspect the issue is the dll call and NOT LV.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 11
(4,002 Views)

Thank you Ben,

You deserve your first set of stars of the day... 🙂

I did read the word dll... but the lack of cafeine this morning scrambled the data before they reached my brain cells.

Thanks for pointing that out.  🙂

Now, it's time for Java (not the sw-dev).

Later..

JLV

 

*** gone on coffee break ***

😄

Message 5 of 11
(3,994 Views)
yes my DLL is thread safe. Does it mean that every call to DLL function has to be reentrant (I have almost 12 DLL calls in the subVI)?
0 Kudos
Message 6 of 11
(3,989 Views)

Only the ones that need to run in parallel.

If you still have trouble after doing what JLV suggested and fixing the appropriate dll calls, post your code so we can comment further.

We do much better with visual aides.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 11
(3,981 Views)
For precisions:
I run WinXP.

I mean by "really" at the same time: to execute approximately at the same time. No real time is needed.

I've tested with a Delphi program that the PC is able to handle both channels at the same time and it takes around 33s. Only 3s overhead compared to a single channel. That is enough for me.

I have more question to understand better:

If a sub VI execution property is "reentrant", does the execution of this subVI happen in a new thread?

In this case if the execution property of DLL calls is "UI thread" and the sub VI is "reentrant", are the DLL functions executed in the subVI thread or still in the main UI thread?

You can have a look at attached document but I'm not sure it will help (LV 7.1).


Finally should I set subVI, subsubVI;-) and all DLL calls in reentrant?

thank in advance
0 Kudos
Message 8 of 11
(3,965 Views)
Just a precision because I'm not sure I wrote in an understandable way.


Parallel for me means that the 2 instances of the subVI can run asynchronously without blocking the other one. Exactly like 2 asynchronous threads.
0 Kudos
Message 9 of 11
(3,962 Views)
thank you both, I can now run simultaneous 2 channels in 31s.


I now better understand "reentrant feature" grant to your descriptions.


many thanks again
Message 10 of 11
(3,947 Views)