LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is this set of case statements not executing in parallel?

Solved!
Go to solution

I have the following SubVI:

 

LabView-Parallel-Cases.jpg

 

I had a similar version that had specific cases for specific devices but I wanted to make it more generic. The GET ALL DATA SubVI is re-entrant and I have tested them working in parallel before. I am wondering if the Merge Errors function is preventing the cases from working properly. Maybe having the returned error from the SubVI on the top terminal will make a difference? Just trying to understand what's going on.

0 Kudos
Message 1 of 29
(3,697 Views)

Data Flow!

 

Each case structure is dependent on the pink cluster wire and the error wire that is coming out of the case structure above it.

 

I would recommend you learn more about LabVIEW from here. How to Learn LV

 

What are you really trying to do?  There is a lot of redundant code here.  It looks like it should either be in a subVI, or the code belongs in a For Loop.  Wny do want these case structures to run in parallel, which they can't because each one is dependent on another one?

Message 2 of 29
(3,683 Views)

I thought I understood data flow. So, you are saying In this situation, the data flowing into the case structure prevents the whole case from executing? Even the parts of the case that are not dependent upon the data coming into the case? If that is the case, them maybe I don't understand data flow as well as I thought.

0 Kudos
Message 3 of 29
(3,671 Views)

Somewhere I think there is a decent writeup on what dataflow means, but I can't find it.

 

I can summarize it in two principles.

1.  A node (and that could be a function, a subVI, a structure) cannot execute until all inputs to it are available.  (So no, a case structure can't execute until all of its input tunnels have data present on them.)

2.  A node can't complete until all code inside of it has executed.  (Which is why data can't flow out of an output tunnel of a case structure early.)

 

 

EDIT:  I googled and found these links on the NI website:

Going With the (Data) Flow

Dataflow Programming Basics

 

 

Looking at your code, that looks like it should just be a For Loop with autoindexing tunnels on both the input cluster and the output cluster.  In newer versions of LabVIEW you can even set For Loops to be parallelizable.  (if the internal code allows it, LabVIEW will tell you if it can't).  Then each iteration can run in parallel.

Message 4 of 29
(3,664 Views)

Thanks for the clarification. That makes sense. As a traditional programmer, I sometimes find myself trying to do things in "old" ways. So, now I need to figure out a way to make this generic and still get the parallelization. I previous tried a parallel loop but ran into the same issues. I guess I am going to have to simplify the dependencies. The critical part is to get the GET ALL DATA SubVI to execute in parallel as they have timeouts in them that can be up to 10 seconds. Just need a better way to provide the device inputs without knowing the size of the array. Thanks again for the help and the links you provided.

0 Kudos
Message 5 of 29
(3,640 Views)

Here is the solution I came up with. Still testing to verify that the changes work as intended. If anyone has a better solution, I would love to see it.

 

LabView-Parallel-Cases-Solution.jpg

0 Kudos
Message 6 of 29
(3,629 Views)

LabVIEW programming is based entirely on dataflow and parallelism. This is incredibly powerful and has lead to its success over the years (coupled with the graphical programming), but is usually one of the first things that new developers stumble over. The Highlight Execution feature is a great way to watch how your application utilizes dataflow.

 

Your second case structures are still going to rely on each other. Why are you duplicating code so much and what is the point of the Greater Than operator and then indexing?? This can all be simplified in to a For loop and you can set up parallelization on the For loop to optimize your processor usage if you want.

Get All Data.png

This goes through each element in the array, which I think is what you're trying to do with your Greater Than operator. If the boolean from Get All Data is True, it includes it in the output array. If it's False, it doesn't.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 7 of 29
(3,617 Views)

James,

 

Why the true constant wired to the conditional tunnel?

 

Arcus,

Why does the Get All Data subVI have 10 second timeouts in it?  What is it actually doing?  Where is it getting data from?

You may need to make sure that the subVI is set for reentrant so multiple copies of it can be run simultaneously.  But depending on what that subVI is doing (like accessing a shared resource), that may not be a good idea.

Message 8 of 29
(3,604 Views)
Solution
Accepted by topic author Arcus111

 


@RavensFan wrote:

James,

Why the true constant wired to the conditional tunnel?


I was simulating his subVI, which has a boolean output. He didn't share his code so I don't have the subVI itself.

Get All Data.png

 

 

I see now why OP did it without a For loop, if he has more devices than he has cores. The For loop could save him coding duplication for at least the number of cores.

 

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 29
(3,594 Views)

The subVI must be reentrant otherwise the code will not execute in parallel.

Marc Dubois
0 Kudos
Message 10 of 29
(3,577 Views)