Queue implementation and adoption of parallel loops

I did here a small pseudo-device code to learn the parallel queue and loop execution.

I need to stop the loops at the same time, so I used a local variable of an indicator and the program.

The problem is in the VI attached below the loops are stop when I press the button stop in the front panel, but the program does not, its still in the running.

It only happens a few times. I noticed that when the loop the first loop interactions are more the second loop the program stops, but when the matter is vice versa it doesn't

Please help me understand why is this.

If you aren't given enqueueing, then Dequeue functions will just sit and wait indefinitely.  Not what you want here.

I don't like the idea of using a local or global variable to put an end to your curls.  Yes, there are places where it is the best option.  But that should be avoided when possible.

I used destroying queues to stop the loops of the consumer.  But there is a flaw in that major: data loss.  If you queue 100 items and then destroyed the queue was not withdrawn all data will be lost.  In some situations, that's fine.  With most of my applications, which is not allowed.

So I like to do is use the data of the queue to send a shutdown command.  In your case, I would like to send an empty array to tell to stop the loop of consumer.  There is a very simple function in the range of comparison to check an empty array.

Tags: NI Software

Similar Questions

  • global variable functional to read and write data from and to the parallel loops

    Hello!

    Here is the following situation: I have 3 parallel while loops. I have the fire at the same time. The first loop reads the data from GPIB instruments. Second readers PID powered analog output card (software waveform static timed, cc. Update 3 seconds interval) with DAQmx features. The third argument stores the data in the case of certain conditions to the PDM file.

    I create a functional global variable (FGV) with write and read options containing the measured data (30 double CC in cluster). So when I get a new reading of the GPIB loop, I put the new values in the FGV.

    In parallel loops, I read the FGV when necessary. I know that, I just create a race condition, because when one of the loops reads or writes data in the FGV, no other loops can access, while they hold their race until the loop of winner completed his reading or writing on it.

    In my case, it is not a problem of losing data measured, and also a few short drapes in some loops are okey. (data measured, including the temperature values, used in the loop of PID and the loop to save file, the system also has constants for a significant period, is not a problem if the PID loop reads sometimes on values previous to the FGV in case if he won the race)

    What is a "barbarian way" to make such a code? (later, I want to give a good GUI to my code, so probably I would have to use some sort of event management,...)

    If you recommend something more elegant, please give me some links where I can learn more.

    I started to read and learn to try to expand my little knowledge in LabView, but to me, it seems I can find examples really pro and documents (http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/ , http://forums.ni.com/t5/LabVIEW/Community-Nugget-2009-03-13-An-Event-based-messageing-framework/m-p/... ) and really simple, but not in the "middle range". This forum and other sources of NEITHER are really good, but I want to swim in a huge "info-ocean", without guidance...

    I'm after course 1 Core and Core 2, do you know that some free educational material that is based on these? (to say something 'intermediary'...)

    Thank you very much!

    I would use queues instead of a FGV in this particular case.

    A driving force that would provide a signal saying that the data is ready, you can change your FGV readme...  And maybe have an array of clusters to hold values more waiting to be read, etc...  Things get complicated...

    A queue however will do nicely.  You may have an understanding of producer/consumer.  You will need to do maybe not this 3rd loop.  If install you a state machine, which has (among other States): wait for the data (that is where the queue is read), writing to a file, disk PID.

    Your state of inactivity would be the "waiting for data".

    The PID is dependent on the data?  Otherwise it must operate its own, and Yes, you may have a loop for it.  Should run at a different rate from the loop reading data, you may have a different queue or other means for transmitting data to this loop.

    Another tip would be to define the State of PID as the default state and check for new data at regular intervals, thus reducing to 2 loops (producer / consumer).  The new data would be shared on the wires using a shift register.

    There are many tricks.  However, I would not recommend using a basic FGV as your solution.  An Action Engine, would be okay if it includes a mechanism to flag what data has been read (ie index, etc) or once the data has been read, it is deleted from the AE. 

    There are many ways to implement a solution, you just have to pick the right one that will avoid loosing data.

  • How to start and stop two parallel loops?

    Hello

    I want to control two parallel loops with different timing in a vi. Second, it means that to start the loop 1, roll 2, stop 1 or 2 restart loop 1...

    But if loop 1 turns that I can't start looping two then reverse.

    Can someone help me and show what is bad in my example?

    Thank you

    Christian

    Hello Christian,.

    The reason why you can't do what you want is actually quite simple.

    You have an external loop which is 'on' the two inner loops.

    So when you stop one of the inner loops, the outer loop will still be in the same iteration until the other inner loop ends - stop the other inner loop.

    You can see very easily if you explore the outer loop iteration count - only when both loops internal, it is incerment.

    So, to do what you want, you need to make them independent - you need two external loops.

    Check my attachtment, see if that's what you need.

    Hope this helps,

    Paulo

  • How to handle errors in two parallel loops?

    Hello

    I have a loop that contains a structure of event and a second parallel loop that reads digital inputs.

    My question is:

    (a) how can I manage the errors of the various events? So, if in event1 is a mistake that event2 presented as input and can react to this topic. Currently, all events begin with "no error".

    (b) what can I do with the second loop? It is also always startin "without error" and doesn't know anything if there is a mistake in loop1.

    Is this only possible with a global variable?

    Thx for the help

    Create a user-defined event gets triggered whenever an error occurs. The input data to the event must be a cluster of error within another cluster - you'll see why when you go to use it.

    Now create a Subvi when it is called with its cluster of input error indicating an error, it raises the event you created above, otherwise, it does nothing. Install the Subvi in two loops after everything else.

    Register for the user on the structure of your event event and put what you want to happen when an error occurs in its event handler. Probibly should give you the option of quiting. If an error occurs in each loop the same evnt will be drawn and you will have the chance to stop.

    Mike...

  • Closure of a state machine in queue event with several parallel loops

    I am trying to find the best way to stop a program that consists of an architecture of State machine in line waiting for event with several parallel loops. Can anyone recommend the best way to achieve this in my attached VI? (To browse the forum, this seems to be a frequently asked question, but I have not found a solution that works for me.)

    I look forward to any comments on my as well code, if someone is willing to offer it.

    My program needs:

    If the user press the 'Stop' button, the program should prompt the user with "are you sure you want to stop the program?" and then return to a State of rest or move forward to stop the program. In addition if there is an error, the program should prompt the user to ' clear the error and continue, or stop the program. Then back to the idle state or move forward to stop the program.

    Architectural details:

    The program consists of 3 parallel loops: (1) a loop of event management that places different States of a queue of the State, (2) a State Machine that enters the State that is removed from the queue of the State and (3) a loop error/Shutdown, which deals with errors in the error queue management.

    During normal shutdown, where running handling loop in the case of event 'Program.Shutdown' and 'Shutdown' and the 'Idle' States are added to the queue of the State. In the state machine, the State of 'Stop' is invoked. Special "5000" error code is added to the queue of the error. In the loop of error handling and stopping, "5000" error triggered a prompt that asks the user if they want to stop the program. If the user chooses not to stop, a notifier StopNotif is sent to the State of 'Stop' and 'Program.Shutdown' event case with notification 'Go '. If the user decides to stop, the Notifier sends the notification "Stop". Loop and event management State Machine ends when they receive the notification "Stop".

    In case of error, the program behaves in the same way: If the user chooses to clear the error and continue, the program returns to the status "pending".

    HOWEVER - if the user chooses to stop the program, the program crashes. The author of the notification that is sent to stop the loop of events and State Machine management cannot be read because event Program.Shutdown and the stop State (which contain the function "Waiting to notify") are not active.

    I was able to activate the stop State by Queuing in the loop of error/Shutdown management. But I don't know how to activate the "Program.Shutdown" event by program and thus access the function "Waiting to notify" inside.

    I tried to put the function "Waiting to notify" outside the structure of the event, so the event-handling loop never ends. Placing timeouts on the "wait for declaring" and the structure of the event makes the programme of work, but I want to avoid using timeouts because I don't want to turn my event program into a program of polling stations. I would also avoid using variables or nodes property to stop loops, because that requires the creation of a control/indicator for something that the user does not need to interact with.

    Thank you!

    First of all, close the notifier outside loops with your queues.  Second, you must use a user event to send the message to the event structure loop so that it stop in the case of the stop on an error.

  • Parallel loops in a Subvi RT in real-time and not

    Hi all

    I seem to remember learning (obviously not well enough) on a cRIO (vxworks) that if there were a Subvi with two parallel loops and loop fell asleep due to a wait function the other loop also be forced to sleep as they are executed in the same thread.

    I have a 2 questions:

    (1) is this completely wrong?

    (2) is also true on a normal windows OS and if so how can I test it because I tried and couldn't seem to see this behavior?

    Kind regards

    Steve.

    Hello

    (1) is this completely wrong?

    Not completely. If you have to screw (or loops) set up as a time critical (priority) and the other goes to sleep, the entire wire goes to sleep, so also the other VI (or loop) goes to sleep. But notice that it is only when configured as critical moment!

    (2) is also true on a normal windows OS and if so how can I test it because I tried and couldn't seem to see this behavior?

    Lol if a standby under Windows, just the loop loop sleeps.

    Christian

  • VISA series Loopback speed and precision with double loops and a queue

    I'm working on a test of communication between 2 PCs. I test communication series RS-422 ports by using a simple loop. PC2 wrote continuous data at 38400 baud to PC1 (LabVIEW test code is here). PC1 reads the data and writes the data to the same port as soon as possible. PC2, reads the data and compares to what should be returned. I can get the highest speed is a speed of about 37300. Because it is continuous, finally that I get an error because the buffer overruns (read and write buffers are 65KO).

    It seems that VISA writing takes a lot longer than the VISA read. I do read/write asynchronous operations. I've read a fixed amount of data (1024 bytes) and then queued data to write in another loop. My timeout is set to 0.5 seconds, which is much time opf at 38400 baud (4800 bytes/second). I played a bit with these numbers, and they are the best I can get. If I increase the data read to 2 KB, the queue members increase. If I'm going too low, I start getting the data in the input buffer overrun.

    Anyone had experience with this type of test? The code is attached. Please take a look and see if I'm doing things correctly.

    Michael

    I do not know if this explains a gap between what you expect and what you found in 0.8 seconds, but you have added another level of complication in using the digiboard.  You don't have a real serial port, but a simulated serial port which is hung at the end of a USB bus.  The digiboard software creates a virtual experiences, and so its driver software and firmware on the side of the Board of Directors of the USB bus must manage some translations to go a number of compote, transfer on the bus and decode the Compote number so that it knows which 8 physical ports that it must send the message to.  You can see delays in translation at each end so something in the USB itself Protocol where it needs group information.

    If you have another, a different brand of the serial ports, you can use, you might want to try one of these to see if you get similar or different results.  But I don't think it's a good idea to try to test the limits of a serial communication device using hardware that adds the other layers of the communication protocol and therefore complicated results.

  • Abort several parallel loops in FPGA environment

    Hi all

    I developed a LabVIEW FPGA code that performs two parallel loops.  The first loop monitors the external positioning sensors and the second loop provides the control for the system under test algorithm.  I am trying to incorporate a condition of 'kill' based on the positioning of external sensors that works similarly to the button cancel in the toolbar of LabVIEW, but I was not successful in finding a solution based on local variables/registrants/etc. in the FPGA coding environment.

    Unfortunately, I can't provide live code; However, the loop control algorithm contains a structure rather long sequence inside the while loop, which will have to be terminated immediately arriving at a threshold of the sensor reading.

    Does anyone have a suggestion on how to implement such an order of demolition?  I really appreciate the help and if I can provide any additional information, please let me know.  Thank you very much.

    You will need to replace the structure of sequence with something that can be stopped.  The simplest solution is a state machine: you put a case structure within a while loop.  The while loop contains a shift register that indicates the current status.  Move each frame of the sequence in another case.  Then, add some logic that checks if the State of abandonment has been reached, and if yes, proceed to a case of "demolition" instead of regardless of the shift register contains.

  • out of digital data from parallel loops

    I created a state machine which will choose a case of 0-23 with a forward and back button.  in each case, I try out a 6-bit word that will be different for each case. However, the data in each case will be displayed in the function of digital writing once you press the stop button. I unde stand I have 2 parallel loops, but I'm not sure how to get around this problem. Ive set my vi

    LabVIEW follows the stream, then your second loop will be waiting for your data of your stop button. Look for the producer / event examples using queues consumer who is a much better way to solve your problem.

  • How to stop the 2 parallel loops

    Hi all

    I have a vi (see attached example) that can be closed in 2 ways:

    (1) user has pressed a button 'Quit' (with a LATCH action) on the GUI.

    (2) the user tries to close the cover by pressing the Red "X" in the upper right.

    The vi contains 2 parallel loops: a main loop that contains the actual code and a 2nd loop containing a stop of vi events.

    The problem is, while the "narrow Panel?" event works very well and finished the 2 loops, isn't the event "value change.

    Then, when I press the button Exit the vi does not stop.

    Any good idea how should I apply it?

    From my experience, a ValueChange event is not raised when you write to a local variable.  I see two quick options:

    You could write the value by using the Value property node (Signaling) (which raises the ValueChange event).

    Or you could simplify things a bit and just use a local variable.  I prefer this option.  See attachment.

  • Wait queue element and then rinse queue

    I then process in a separate loop and work with a producer consumer design to read data from a data acquisition (number crunch, update locations, write to produce results).  The rate of data acquisition can be very variable, so there are some cases where the producer fills the queue more quickly that the consumer can handle it (one at a time).  So I changed the loop of consumer to use RAS queue instead of dequeue and batch process all recent items.  This works well and allows a much faster operation.  The downside, I've noticed, is that, when the producer loop runs much more slowly than the loop of consumer, hunting generates the queue runs without data to pass.

    What I am wondering if there is nothing to wait for the elements of the queue (as done dequeue) and then clear the queue, without using too broad.  I guess I could use the status of the queue in a loop and then emptying the queue, but I'm guessing that this would lead to a significant overhead when I turn at higher speeds.

    The only alternative I can think of is to put the write file a third loop with another queue because it's probably slowing down the main consumer loop and then put the loop main consumer towards the transformation of one item at a time.  But it seems that there should be an easier way to do it.

    Any thoughts, suggestions or generally better ways to handle this?

    Thank you

    Tim

    Use Preview queue and do not wire out of the element. It has a timeout, as element Dequeue. Put empty the queue directly after this one. Or, use Dequeue followed by emptying the queue and add the output from the Dequeue item on the output table to empty the queue.

  • Why build on average has side effects on the parallel loop

    It is a simple parallel loop to process the average value of each waveform.

    When you use tools-> profile-> find parallelizable loops, it is said:

    This loop For may or may not be safe to parallelize. Warning (s):
    -One or more nodes in the loop For can have side effects.

    So, why? It is not reentrant?

    The average function calls an internal function of NOR, which may (or may not / be reentrant.)  You can always code to the top of your own average code fairly easily and could make it reentrant - that would probably solve your problem.

    Bob Schor

  • Control and Simulation in a loop / while loop with TCP/IP reading / writing of synchronization

    Hello, I have a problem with reading TCP/IP and written in two loops. The problem is NOT to get the two loops to read and write to and from the other. This has been accomplished. My problem is when I run control and the loop simulation on my laptop and the while on a RTOS remote on the controller on-Board of LabVIEW in a remote PXI chassis, the while loop the remote system running on four 4 times faster than the loop control and simulation on my laptop. In other words, for each iteration of the loop control and simulation on my laptop, there are 4 four iterations of the while loop on the remote system. I need to know how to get a degree of kinship (1:1) with these iterations of the loop. When I run a longer simulation in real time, say 10 seconds, the control and Simulation loop begins to slow, i.e. the simulation time slows down until it is no longer in real time and the "Late Finish"? Parameter is set to true and the LED lights and continues to stay lit. At this point, the system destabilizes due to what I believe is being well sampling rate too discreet and I have to end the simulation. How can I get a ratio of one to one between the loops and also to avoid slowing the loops causing destabilization?

    To give an overview of my application, I implement a control system in a network, seen in "image2.png". This is achieved using my laptop as a subsystem 1. Reference signals are generated from the laptop and the error signal is produced. Control measures taken and the control signals are sent via TCP/IP to the remote system. Position feedback is returned, and the process repeats. My system has Core I7 Procs w / 3 GB of RAM, up to 1 GB/s speed via ethernet and LabVIEW 2011 installed with all necessary modules and networking tools. The attached VI Custom_Wireless_Controller works on my laptop. The remote system I'm working on that has the 7830 NI R Series with FPGA card. OTN runs on the PXI chassis with an enbedded controller that has networking capabilities of up to 100 MB/s via ethernet. I use the FPGA for the acquisition of data and apply control signals to my plant. The plant is the PCE twist connected to the FPGA through the cable of the ECP - RIO of NOR. Subsystem 2 is this side of the CNE. The FPGA collects position, he sends to the controller via the network, receives signals from the network drive and writes signals to the plant power amplifier that operates the plant. This process is repeated and the VI and is titled Custom_Wireless_Plant.

    I appreciate the help really and look forward for her and for any question!

    Well, the first step is to understand what you have set up right now. Your control and Simulation loop on the side of the controller is configured as 'Runga Kutta 4' and you have a loop timed on the other side. In addition, you have the primitives of TCP/IP on the control and the Simulation diagram and means he will perform (a message) on the size of each minor step, which in your case is 4.

    So, you have two options:

    1. replace the Solver side controller Runga Kutta 1 (this must synchronize loops)

    2. hold RK 4, but create a Subvi around two primitives of TCP/IP and configure from the VI to run than the major (continuous) step-size. If you do it right, you should see a 'C' on the upper right part of the VI you have created.

    Please let me know if what I said is not clear...

  • For parallel loops run on hearts of dedicated processors?

    I don't think that this is the case; My confusion is due to the fact that the literature regarding this structure addresses using the maximum number of cores the computer in which this codemay run in the dialog box for parallelism but also loop iteration using the CPU Information function to determine the number of instances to parallelize. I suspect that parallel loops For will first of all be decomposed into Tufts/tasks of iteration which will be either in versatile collaboration & and/or multithreaded in a system of priority of execution before they ever get to be mapped to hearts dedicated instance. Is this correct? -literature, I want to talk about is Improving Performance with loops parallel http://zone.ni.com/devzone/cda/tut/p/id/9393, under the guidance of Performance or the help of LabVIEW (multiprocessing and Hyperthreading in LabVIEW). I don't see how this information applies to how the loop bodies parallelized and executed. I hope someone can enlighten me and perhaps others to read these documents.

    Thank you!

    jorgeinSD, thanks for the insightful question. Your second option is correct. Each instance of a parallel loop is in a different bouquet and schedules of delivery system of these Tufts between the available threads. LabVIEW does not bind son to cores for the parallel loop, so threads can switch between the nuclei they run.

    Mary Fletcher

    Software engineer

    LabVIEW R & D

  • While parallel loops is not running

    Hello, I am a program to run a room, and I run in to trouble. I have 5 all in curls that are supposed to be running in the main VI connected by queues. The first is to check the front panel for events. As readers the following two, who are responsible to issue commands to run the House, or give orders, to check the data collected. The fourth is running the House, and give orders, to write the data. Writing takes place in the last loop. After that all loops fire the first time, it seems that only the first and the last still to run. Could someone take a look and tell me where I was wrong?  I'm still very new to labview, so I don't know that it is a small mistake or another.

    Thank you

    Simon

    I think I found my problem. I had to add another element to the queue that is identical to the loop, if I wanted to keep it in that State. I'm still working through it, but I've corrected a few curls up to now. Thanks for the advice everyone.

    Kind regards
    Simon

Maybe you are looking for