Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

cpu USAGE
I have a simple while loop. It doesn't call vi's or do anything except loop.
 In fact, it is completely empty except for a boolean control attached to th
e conditional terminal.
 
As soon as I run the vi, my cpu usage goes up to 50%. Is this normal. I know
 I could put a delay in the loop and reduce the usage. When I do this if I p
ut a 1ms delay in my usage stays close to zero. When I put in a 0ms delay, m
y usage is again about 50%.

 
I found this out because apparently, while looping and doing nothing, it is 
accessing the disk, and the buzzing was driving me nuts. (Not with this whil
e loop, but with a real program that also has a while loop). So I was driven
 to investigate.
 
Is this a labview thing, or does this happen with other programming language
s too?
 
I'm using lv6.1.
 
Thanks.
 
Chuck Gantz

Report this thread to moderator Post Follow-up to this message
Old Post
cgantz2000
12-17-05 12:04 AM


Re: cpu USAGE
It is normal that a loop without any wait statement will consume all availab
le CPU. It will spin as fast as possible. Why shouldn't it? :o
 
A while loop itself does not consume huge amouts of memory, so your other ap
plication certainly has a different issue. Can you post the code? Are you bu
ilding arrays to infinite size? What else is in that other loop?

Report this thread to moderator Post Follow-up to this message
Old Post
altenbach
12-17-05 12:04 AM


Re: cpu USAGE
I'll have to try a simple experiment when I get home. I'll write a console a
pp in C with just a while loop and see if the same thing happens.
 
I can't really send the other app, but it is essentially a while loop that w
aits for me to press a button before doing measurements et al.
 
Normally it just sits and waits. The problem is that if I try to run somethi
ng else (specifically Excel) while the program is waiting, the pc is so
 sluggish that I can't do anything. As soon as I turn off my LV program, the
 pc is fine.
 
Chuck Gantz

Report this thread to moderator Post Follow-up to this message
Old Post
cgantz2000
12-17-05 12:04 AM


Re: cpu USAGE
Like Altenbach said, when you have no wait, the loop tries to run as fast as
 possible, regardless of what you have in it and regardless of what other pr
ograms want. This is probably specific to the LV compiler. I'm not sure how 
parallel programming works
in other languages. Can you write a loop which will be truly stand-alone (fr
om the compiler's point of view)? If you can, how do you control its timing?
 Using wait statements?
If you put a 0 ms wait, LV should try to run the loop as fast as it can as l
ong as no other tasks are requesting the CPU, which is probably why you're s
eeing a high CPU usage there.

Report this thread to moderator Post Follow-up to this message
Old Post
tst
12-18-05 12:00 AM


Re: cpu USAGE
Thanks all.
I went home and wrote my simple C program with a while statement:
int _tmain(int argc, _TCHAR* argv[]){  while( true) {} return
 0;}
When I ran it my cpu usage went up to 50%, just like with LV. Opened my eyes
. I thought the OS would somehow regulate this. Now I know better.
I also now know why I see the Wait for nearest ms vi in so many examples. I'
ll just start to include it myself.
 
Chuck Gantz

Report this thread to moderator Post Follow-up to this message
Old Post
cgantz2000
12-18-05 12:00 AM


Re: cpu USAGE
cgantz2000 wrote:

I have a simple while loop. It doesn't call vi's or do anything except loop.
 In fact, it is completely empty except for a boolean control attached to th
e conditional terminal.
 
As soon as I run the vi, my cpu usage goes up to 50%. Is this normal. I know
 I could put a delay in the loop and reduce the usage. When I do this if I p
ut a 1ms delay in my usage stays close to zero. When I put in a 0ms delay, m
y usage is again about 50%.



As an addition note, it would be more typical that the loop consumes 100% of
 the CPU. Do you have a dual-core processor?
 
You have three scenarios (approximate times for my PC, normal priority, debu
gging enabled):

- No wait: The loop runs as fast as the CPU allows.Only <a href="h
ttp://ideasinwiring.blogspot.com/2005/05/55ms.html" target="_blank"> every 5
5ms</a>, it checks if something else needs attention, then continues. The lo
op spins about 100 million
times/second. Actual rate depends on CPU speed.

- 0ms wait: The loop runs as fast as the CPU allows. After every iteration, 
it checks if something else needs attention, then continues. This slows down
 the loop rate to about 3 million iterations/second. Actual rate depends on 
CPU speed.

- 1ms wait: Same as case (2), but the loop waits ~1ms before continuing. Sin
ce we just saw that one loop iteration takes only a few nanoseconds, the CPU
 is nearly 100% idle. The loop spins exactly 1000 iterations/second, irrespe
ctive of CPU speed.

Cases (1) and (2) both should consume 100% CPU. There is always somethi
ng to do, no time for idling. Right?

Report this thread to moderator Post Follow-up to this message
Old Post
altenbach
12-18-05 12:00 AM


Re: cpu USAGE
On my main machine at work running LV with just a while loop and no del
ays, and my pc at home running the C while loop, 50% of the resources were u
sed. On the machine at work running the "real" LV program, the one that actu
ally does something, 100% o
f the resources were used. No dual processors.
I don't know the last machine used twice as many resource as the other two, 
but it is an older machine and may have other issues. I don't really know wh
at was causing the noise on my desktop pc when the while is running. I assum
ed it was disk access simpl
y because there is not much else in the pc that causes noise, but it could b
e something else.
 
Chuck Gantz

Report this thread to moderator Post Follow-up to this message
Old Post
cgantz2000
12-18-05 12:00 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

LabVIEW archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:22 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.