Jump to content

PLease help a newbie with a "Basics I" course question


richlega

Recommended Posts

I am working through the LabView Basics I course and I have run aground on this example.

The Flash example and quiz in the Dataflow directory of the exercises shows the attached code and poses the question: "Which Tone Measurements will execute first?

I immediately answered incorrectly and was slightly confused by the correct answer.

I have asked four "seasoned" LV programmers in the office (I am the newbie here with nearly 25 years experience in C programming) the same quiz question and they all answered incorrectly (one insisted that NI's answer is wrong).

I understand the answer and the position of the language definition, but my "logic brain" is still stumbling over this.

Please discuss.

post-8916-1204226154.jpg?width=400

Link to comment

Could you add a poll? (or is that Premium only?)

I'd go for answer 3!

It could be possible that the thread calling the upper tone will be frustrated by Windows (since it calls some dll somewhere), and that the filter will go first and the lower tone might get a headstart.

Ton

Link to comment

QUOTE(richlega @ Feb 28 2008, 11:18 AM)

I am working through the LabView Basics I course and I have run aground on this example.

The Flash example and quiz in the Dataflow directory of the exercises shows the attached code and poses the question: "Which Tone Measurements will execute first?

The answer that seems obvious is "the one near the top", but I agree with Ton. Once the data branches there is no way of knowing the precise execution order of the two parallel branches. Especially in a non deterministic operating system.

Link to comment

I agree with Ton. There is no way to tell which one of the two executes first.

"Most likely" the top one will execute first, but "most likely" is not "definitely".

The only way you could tell "definitely" which one executes first is if one of the two took an output from the other as an input (or was contained in a structure that needs an output from the other).

Link to comment

QUOTE(richlega @ Feb 28 2008, 02:18 PM)

There is no way to determine which one will finish first (assuming execute means finish first), with the information provided. The only thing that can be stated for certain is that the bottom tone will not start execution until the filter vi is completed. There is no dependency between the top tone and the bottom tone so it is simply a mater of which process takes longer to execute the top one or the sum of the bottom two. If by execute they mean which one starts first, the answer is the same the reason is different. Since there is no data flow between the top tone and the bottom tone it is up to Labview to decide the execution order. Many factors are considered by Labview when deciding execution order (in parellel processes) , a look at the block diagrams would enable a better guess, but it would still be a guess.

Link to comment

I've gotta go with the top one - VIs will execute when they have all of thie inputs satisfied, and, based on dataflow, the top will one have it's inputs satsified before the bottom one will. There's question on which order the top tone measurement and the filter VIs run, but I'm pretty sure that the top tone measurement VI will run before the bottom tone measurement VI.

QUOTE(van18 @ Feb 28 2008, 03:41 PM)

...(assuming execute means finish first)...

I'm pretty sure the question means start first, not finish first.

Link to comment

QUOTE(crelf @ Feb 28 2008, 02:00 PM)

I've gotta go with the top one - VIs will execute when they have all of thie inputs satisfied, and, based on dataflow, the top will one have it's inputs satsified before the bottom one will.

In practice that's true, but is it guaranteed to be that way? I think the compiler could generate code so that the bottom one runs first, and everything would still be formally valid.

My answer would be C, but at the same time I'd bet you all a round of beers at NI Week that the top one actually executes first, by the same reasoning as crelf.

Link to comment

Oh, this is a fun one to answer.

Short version:

The LV Basics answer is "there is no way to know" because...In a dataflow language, there is no guarantee which branch of a parallel branch will execute first.

Long version:

QUOTE(crelf @ Feb 28 2008, 03:00 PM)

No.

VIs will execute when they have all of thie inputs satisfied

should be

VIs CAN execute when they have all of thie inputs satisfied

That is, they are now placed on the run queue for the next available thread to execute. There's no telling whether the next available thread will grab the top Tone Measurements or the Filter Signal, and, if it grabs Filter Signal, there's no way to know that it won't go ahead and execute the bottom Tone Measurements before going back to do the top Tone Measurements. Further, if there are multiple threads in your operating system, each thread may grab one branch, and then it is up to the operating system to decide which thread gets to run first.

It is possible that, depending upon how the underlying code of these nodes is written, the LV compiler MAY choose to always have one specific execution order for these nodes, but there is nothing that guarantees that order. Even if you managed to get the compiler into a state where it chose the scheduling to guarantee the execution order, a slight shift in nodes, even downstream nodes, could make the compiler make a different choice.

So, what choice will the compiler make in this particular example?

We have Tone Measurements on the top branch and Filter Signal on the bottom branch. Let's assume (because it is reasonable to do so, not because I actually checked the implementation) that the Filter Signal's input and output terminals are inplace to each other. The Tone Measurements node is thus a "read only" node -- it uses the value of the input to calculate its outputs, but it doesn't actually modify the input. The Filter Signal does modify the value of its input and passes it through as an output. Because the Tone Measurements node is a synchronous node (it doesn't do any waiting for hardware or timer interupts, just math operations), I suspect that the LabVIEW compiler will declare all three of these nodes to be a single "clump" (aka unit of selection for threads on the run queue), and will schedule them to always run top Tone Measurements, then Filter Signal and then bottom Tone Measurements. But this is a guess from me based on what I know of the compiler and what I know of the description of those three nodes. In general, I would stick with answer number 3:

There is no way to know.

Here is one that is definitely undecidable -- there is no way to know which of these Tone Measurements will execute first:

http://lavag.org/old_files/monthly_02_2008/post-5877-1204235944.png' target="_blank">post-5877-1204235944.png?width=400

Link to comment

QUOTE(Aristos Queue @ Feb 28 2008, 04:59 PM)

Oh, this is a fun one to answer. Short version: The LV Basics answer is "there is no way to know" because...In a dataflow language, there is no guarantee which branch of a parallel branch will execute first. Long version:No. VIs will execute when they have all of thie inputs satisfied should beVIs CAN execute when they have all of thie inputs :Undecidable.png]

Also, isn't it true that if a subvi is not reantrent, and it is being called by other callers, the subvi will have to wait untill it is not busy running somewhere else, before it can execute for another caller. That was a ugly sentence.

If the top VI takes a long time to execute, and it is already running somwhere else in the code (if this chunk was a small part of a larger application), it will not execute for this caller untill the other caller has finished executing it. In addition, there could be other callers of this VI already waiting in line, in that case it would have all its inputs but may have to wait awhile before it can execute for this caller.

Link to comment

QUOTE(Aristos Queue @ Feb 28 2008, 04:59 PM)

The LV Basics answer is "there is no way to know" because...In a dataflow language, there is no guarantee which branch of a parallel branch will execute first.

So the real answer is that you shouldn't need to ask the question :) If you've written a VI like this, then it's irrelevant which one goes first because, if it was relevant, you'd have used dataflow to force execution order.

Link to comment

QUOTE(crelf @ Feb 28 2008, 05:01 PM)

So the real answer is that you shouldn't need to ask the question :) If you've written a VI like this, then it's irrelevant which one goes first because, if it was relevant, you'd have used dataflow to force execution order.

I agree. More proper choices would be:

  • The one near the top of the block diagram.
  • The one near the bottom of the block diagram.
  • No reason to care. :thumbup:

Link to comment

QUOTE(van18 @ Feb 29 2008, 12:14 AM)

Also, isn't it true that if a subvi is not reantrent, and it is being called by other callers, the subvi will have to wait untill it is not busy running somewhere else, before it can execute for another caller. That was a ugly sentence.

Yes, but only if it is not reentrant. I'm not sure how express VIs handle the actual implementation VIs at run-time, but the VI behind that express VI is reentrant, so my guess is that this doesn't come into play in this case.

Link to comment

QUOTE(Yen @ Feb 29 2008, 09:40 AM)

Yes, but only if it is not reentrant. I'm not sure how express VIs handle the actual implementation VIs at run-time, but the VI behind that express VI is reentrant, so my guess is that this doesn't come into play in this case.

Express VIs are reentrant, it was one of the major drawbacks during development of them. Because LV7 didn't have reentrant debugging, ask Jeff Washington for the full story.

Ton

Link to comment

QUOTE(richlega @ Feb 28 2008, 01:18 PM)

I am working through the LabView Basics I course and I have run aground on this example.

The Flash example and quiz in the Dataflow directory of the exercises shows the attached code and poses the question: "Which Tone Measurements will execute first?

My first reaction was answer "C" and I'm gratified to read that Much Smarter People had the same response. I'm just curious to know what the "correct" answer was, according to the example.

Link to comment

QUOTE(eaolson @ Feb 29 2008, 10:21 AM)

My first reaction was answer "C" and I'm gratified to read that Much Smarter People had the same response. I'm just curious to know what the "correct" answer was, according to the example.

The "correct" answer was indeed C. BTW this is an excellent post and discussion.

My first intuitive and logical response was A, the top tone measurement would execute first. However ... this is one of those NI "trick" questions. These pop up from time to time on certification exams. Some of us seem to have forgotten the (unwritten) First Rule of NI Tests and Certifications:

The "correct" answer is not necessarily the answer you think is right, but the answer NI wants to hear.

Queue's response made sense. NI writes LV as a dataflow language. And the only way to be certain of any order of code execution is to force the code execution using the data flow paradigm. Good question, great discussion and I'm convinced that "C" is indeed the "right" and only "correct" one. There is no way to be certain which portion of the code will execute first.

Link to comment

QUOTE(PaulG. @ Feb 29 2008, 11:25 AM)

Some of us seem to have forgotten the (unwritten) First Rule of NI Tests and Certifications: The "correct" answer is not necessarily the answer you think is right, but the answer NI wants to hear.

:thumbup:

Link to comment

"Some of us seem to have forgotten the (unwritten) First Rule of NI Tests and Certifications: The "correct" answer is not necessarily the answer you think is right, but the answer NI wants to hear."

QUOTE(crelf @ Feb 29 2008, 11:49 AM)

:thumbup:

True, true.

That phrase is the text version of "finger-nail on the chalkboard" for me. Manitaining my certifications under those rules is probably one of my prime reasons for counting down the days until I retire (2862 days).

Ben

Link to comment

QUOTE(neB @ Feb 29 2008, 09:17 AM)

Manitaining my certifications under those rules is probably one of my prime reasons for counting down the days until I retire (2862 days).

Ben

Just think. After today you only have one more Feb 29th to work!

Link to comment

QUOTE(Aristos Queue @ Feb 28 2008, 04:59 PM)

"VIs will execute when they have all of thie inputs satisfied" should be "VIs CAN execute when they have all of thier inputs satisfied"

So, in summary, the order that the inputs of a VIs are satisfied is not necessarily the order in which those VIs are executed. This is pretty clear when using execution highlighting - sometimes LabVIEW likes to "finish a flow" before it goes back to others that are waiting mid-flow :wacko:

Link to comment

QUOTE(crelf @ Feb 28 2008, 04:01 PM)

So the real answer is that you shouldn't need to ask the question :) If you've written a VI like this, then it's irrelevant which one goes first because, if it was relevant, you'd have used dataflow to force execution order.

No, I think the question is (albeit a trick question) correct. In LV Basics, it is important to make this point so that you realize that if order is important then you need to force execution order. Because if it was relevant, then there is a bug in that code. After all, we only code it correctly after fixing all our bugs. ;)

Link to comment

QUOTE(crelf @ Feb 29 2008, 02:39 PM)

...when using execution highlighting - sometimes LabVIEW likes to "finish a flow" before it goes back to others that are waiting mid-flow :wacko:

Some of us have obviously watched too many diagrams run in execution highlighting mode. :)

Another pattern I noticed is that if more than one "flow" has their inputs available, the thread that was dropped on the diagram first will be executed first.

Ben

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.