Darren's Weekly Nugget 06/12/2006

Darren's Weekly Nugget 06/12/2006

Post by Darre » Wed, 14 Jun 2006 02:10:06


Today I'll talk about something you may not know regarding Flat Sequence Structures.  Check out these two code screenshots:
 
<img src=" http://www.yqcomputer.com/ ">           <img src=" http://www.yqcomputer.com/ ">
 
They look like they do the same thing, right?  Wrong!  One little-known fact about Flat Sequence Structures is that individual frames will execute if they don't have any outside data flow dependencies.  So in the first example, the entire Flat Sequence Structure must wait until the While Loop ends until it can execute.  But in the second example, the first frame of the Flat Sequence Structure will actually run independent of the While Loop, while the second frame must wait until the loop is done.  I remember spending a lot of time debugging some code back in LabVIEW 7.0 that was not behaving as I expected, and this peculiar behavior of the Flat Sequence Structure was the culprit.
 
Why does it behave this way, you may ask?  Well, during development of the Flat Sequence Structure, LabVIEW R&D decided that this kind of wiring scheme should be supported:
 
<img src=" http://www.yqcomputer.com/ ">
 
..and in order for this to be supported, the first frame of the Flat Sequence Structure obviously must execute before the third frame has all its inputs available (since the first frame is *supplying* the third frame with its input).
 
-D P.S. - Check out past nuggets <a href=" http://www.yqcomputer.com/ ;message.id=1669" target="_blank"> here</a>. Message Edited by Darren on 06-12-2006 11:42 AM


Flat_Sequence_Image3.jpg:
http://www.yqcomputer.com/


Flat_Sequence_Image1.jpg:
http://www.yqcomputer.com/


Flat_Sequence_Image2.jpg:
http://www.yqcomputer.com/
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by Darre » Wed, 14 Jun 2006 02:40:08

Yes, the help does mention this fact.  Here's an excerpt from the on-line help for the Flat Sequence Structure:
"Data flow for the Flat Sequence structure differs from data flow for other structures. Frames in a Flat Sequence structure execute from left to right and when all data values wired to a frame are available. The data leave each frame as the frame finishes executing."
But in my defense, when I encountered this behavior, I was using a very early pre-release version of LabVIEW 7.0...I'm guessing the help hadn't been written yet.  ;)
-D

 
 
 

Darren's Weekly Nugget 06/12/2006

Post by Darre » Wed, 14 Jun 2006 03:10:08

I wasn't part of the original decision making process on the Flat Sequence Structure, but I can see how it would be rather restrictive if only certain wires could enter non-initial frames of a Flat Sequence structure.  I haven't ever run into a case where I would need the behavior illustrated in my third screenshot above, but there is the possibility that I will need it someday in the future, and I'm glad it's there just in case. 
-D
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by Ben » Wed, 14 Jun 2006 03:10:09

At first thought, this sounds like a "poor man's" rendevou
Ben
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by Underflo » Fri, 16 Jun 2006 03:40:08

It works pretty well as a simple rendezvous.

I've used this to ensure that all of my state machine states are cleaned up before the queue is destroyed (see attached image).

Was the flat sequence really necessary?  Well, no, but it's pretty clean looking.

Joe Z.


Queue_Dispose.jpg:
http://www.yqcomputer.com/
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by TonP » Fri, 16 Jun 2006 04:40:08

What am i missing (see attachment) where the second frame waits for the first. is this only applicable for non UI-vis?Ton (or did i not understand what Warren said)Message Edited by TonP on 06-14-2006 09:30 PMMessage Edited by TonP on 06-14-2006 09:35 PM


naamloos.GIF:
http://www.yqcomputer.com/


naamloos.GIF:
http://www.yqcomputer.com/
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by altenbac » Fri, 16 Jun 2006 04:40:09

Interestingly, I run ito this behavior a few months where I had two "three-frame sequences" for benchmarking (tick..code..tick in each). I was puzzled for a while that the first tick in each sequence started running immediately even though I "sequenced" the two seqeunces by wiring and output from the last frame of one sequence to the middle frame of the second sequence. Moving the wire to the first sequence cured it. :D
 
Reading the online help somehow would not have helped much illuminating this specific behavior, the description is too condensed for me.
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by altenbac » Fri, 16 Jun 2006 07:10:09


What am i missing (see attachment) where the second frame waits for the first. is this only applicable for non UI-vis?Ton (or did i not understand what Warren said)


 
In your example, the frames execute sequentially of course. Darrens nugget discusses how individual sequence frames execute in relation to other parts of the code. In the example:
<img src=" http://www.yqcomputer.com/ ">
Frame 1 and the while loop can execute simultaneously because there is no data dependency. Frame 2 must wait until both frame 1 AND the while loop have completed.
 
 
 

Darren's Weekly Nugget 06/12/2006

Post by Darre » Fri, 16 Jun 2006 14:40:06

Thanks for answering that on my behalf, altenbach.  I assumed he was talking to some guy named Warren, then I realized how close 'W' and 'D' are on the keyboard.  :)
-D