LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Execution order

Solved!
Go to solution

I need the current time assignment to be executed before case structure (see screenshot). Get Date/Time VI doesn't have error output. So I use date/time output and wire it to the CASE structure. Is it sufficient to ensure execution order (if the value of date/time isn't used in case structure) ?


*** LV2018 ***
0 Kudos
Message 1 of 10
(2,845 Views)

Apply this rule as literally as you can:

 

"Remember that a node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution."  One thing it doesn't mention is that a structure is considered a node when it comes to dataflow.

 

Now you should be able to tell me if this will work or not.  (But if you can't, I can walk you through applying that rule, so don't think I'm leaving you out in the cold.  I just think it would me more satisfying for you if you could figure it out yourself.)

 

FYI, this is where I got the quote from, and it may help you understand dataflow better: https://www.ni.com/getting-started/labview-basics/dataflow#:~:text=Video%3A%20Dataflow%20Programming....

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(2,839 Views)

Bill, I know this rule, it's an elementary LV knowledge.

 

But I think now that the assignment date/time to global variable is "independent" so it can happen even after execution of case structure. The only execution order I can be sure of is: Get Time/Date -> case structure.

 

So solution is to use flat sequence for example.

 

Am I right?


*** LV2018 ***
0 Kudos
Message 3 of 10
(2,813 Views)

Hi, You can use flat sequence to ensure the execution order of Get  Data and time function before the case structure.

Best Regard.

0 Kudos
Message 4 of 10
(2,795 Views)

I don't know this for a fact, but I believe the way you drew it, the local variable assignment is getting done before the execution of the case structure.

 

If you go with the 2 rules that Bill listed.

1.  A node (or structure) doesn't execute until it has all its inputs.

2.  A structure doesn't complete and provide output until all the code inside of it completes

 

you can carry that a step further and consider the wire of the timestamp a sort of structure itself with many branches, and it isn't going to execute any code beyond a branch until it has provided the data to the ends of all of its branches.

 

That is my belief, and if I'm wrong, please someone correct me.  I've wondering this same thing from a long time ago, but I've never seen LabVIEW behave otherwise, but then again, I haven't had that many situations where it mattered.  To be truly sure it executes the way you want, do what Emna said and apply a single frame flat sequence around the writing of the global variable.

 

PS:.  You have an image in your signature line that is not showing up.  It just says File Not Found.

0 Kudos
Message 5 of 10
(2,782 Views)

@billko wrote:

Apply this rule as literally as you can:

 

"Remember that a node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution."  One thing it doesn't mention is that a structure is considered a node when it comes to dataflow.

...

Actually, a structure is a type of node:  Generic.GObject.Node.Structure

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 10
(2,769 Views)

@RavensFan wrote:

I don't know this for a fact, but I believe the way you drew it, the local variable assignment is getting done before the execution of the case structure.

...


Not true.  The order is indeterminant.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 10
(2,768 Views)

Writing to the global variable and executing the case structure occurs in parallel and there is no way to tell what happens first. Both depend on the timestamp and must wait before the timestamp is obtained.

 

(Reading the boolean and getting the timestamp also occurs in parallel, but only the case structure depends on the boolean.)

 

While the case structure does not "use" the timestamp value, it will still wait because that wire is a strong clue to the compiler about desired execution order and will not be eliminated as dead code.

 

Another example:

 

altenbach_0-1594482283877.png

 

0 Kudos
Message 8 of 10
(2,764 Views)
Solution
Accepted by petrnowak

@petrnowak wrote:

Bill, I know this rule, it's an elementary LV knowledge.

 

But I think now that the assignment date/time to global variable is "independent" so it can happen even after execution of case structure. The only execution order I can be sure of is: Get Time/Date -> case structure.

 

So solution is to use flat sequence for example.

 

Am I right?


What I am saying is that you can definitely tell if it's going to do what you expect it to do any applying that rule.  If you can't, you haven't tried hard enough.  In this case, it seems that you were just too tentative about your conclusion.  But don't worry, you were right - you need a flat sequence structure around the writing to the global to make sure the global is updated before the case structure is executed.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 9 of 10
(2,739 Views)

Every time I think I cannot determine what is going to happen (because i'm not sure, not because the code is ambiguous), I force myself to repeat that rule to myself for every node I come across.  Eventually, you understand how it wants to run.  And it's not always the way you want it to run!  😉

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 10 of 10
(2,737 Views)