Jump to content

Loop timing & Execution differences (non-RT system)


Recommended Posts

I use several software timed loops to run in parallel at different intervals to poll 4 serial ports in a Windows XP environment (LV 8.6) while passing the data (via Queues) to an alignment loop running at the fastest data rate loop to align, display, and log the data.

In the past/currently I use while loops w/ a "Wait ms function" placed inside the loop, parallel w/ the code to poll and parse the com ports (I know the "Wait ms" is not the best approach and should probably use "wait until next iteration"). (The poll and parse code executes faster than the wait)

I've tried implementations w/ timed loops in the past, but it seemed the loops weren't serviced as regularly (I will need to revisit that).

MY QUESTIONs If I don't care about the feedback info provided by timed loops:

-What timed loop implementation is most efficient and results in the best performance... a timed loop, while loop w/ wait ms function, or while loop w/ wait until next iteration?

- Differences between a timed loop and while loop w/ a wait until next iteration on a non-RT system?

Information I'm after is performance based (timing, multi-thread, overhead costs) and associated advantages/disadvantages.

(the more technical / under-the-hood the better)

Thanks

Link to comment

A while loop with nothing will be the fastest. But it will hog your processor (although I've noticed 2009 it only hogs 50% instead of 100%) and it will be hit and miss whether other similar loops get in or not. The next is usually a wait ms with a 0 wait time as it allows context switching so your other loops at least get a look in. Timed loops under windows are better used as a periodic function rather than (in the realtime context) a deterministic function since you are still at the mercy of the windows scheduler. The rule of thumb is. if its time critical......don't use windoze!

Link to comment

Thanks, but I'm after a little bit more info. It might've been my first post to the forums, but I'm not new to LabView (been programming 5+ yrs).

Some things I heard / read somewhere over the years that caused my questions.

They may be true, they may not...

- Timed loops only execute on a single thread, regardless of how many loops you have (4 timed loops, 1 thread...doesn't make sense to me?).

- Timed loops are not compatible to run on AMD processors.

Clarity?

Link to comment

Thanks, but I'm after a little bit more info. It might've been my first post to the forums, but I'm not new to LabView (been programming 5+ yrs).

Some things I heard / read somewhere over the years that caused my questions.

They may be true, they may not...

- Timed loops only execute on a single thread, regardless of how many loops you have (4 timed loops, 1 thread...doesn't make sense to me?).

The thread that anything runs in is not dependent on the loop (LV 9.0and "for" loops excepted) but the "Execution System" that you define. Additionally, the number of loops is irrelevent. Its the vi's that count! The max thread count is 8x5x5 = 200 (8 per execution system x 5 execution systems x 5 priorities). The default is 4 per execution system with 0 for background . So if you look in process explorer you will probably see 21 threads (4x5=20 + 1 for LV itself). Therefore, if you have 4 threads and 12 loops in 1 execution system in 1 vi which is at "Normal" priority,then the LV scheduler will split the 12 loops between the 4 threads (black magic NI secret how this is applied....chime in here LV gurus!). If you want to ensure that a single loop runs in a single thread (not documented but works for me). Then run those loops in their own vi and in diiferent execution systems (I use other1 and other2 a lot) and in asingle vi. If you change the threads per execution, then you will see the threads grow in "Task Manager". Bear in mind, that LVpre-allocates threads, so you will only see the difference when youre-start LV.

One further point. Don't confuse parallelism with multithreading. You can run 2 loops in parallel but LV may only run them in 1 thread and "timeslice" between them.

A usefull utility exists in vi.lib\utility\sysinfo\threadconfig.vi where you can change the thread allocations.

- Timed loops are not compatible to run on AMD processors.

Clarity?

- Don't know. None of the PC's we use have AMD processors, but seems a bit unlikely.

Edited by ShaunR
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.