LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

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 the 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 put a 1ms delay in my usage stays close to zero. When I put in a 0ms delay, my 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 while 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 languages too?
 
I'm using lv6.1.
 
Thanks.
 
Chuck Gantz
0 Kudos
Message 1 of 8
(4,097 Views)

Could be a memory resource issue, in that the computer is swapping to virtual memory.

Labview its self won't access your hard disk just to handle a loop, my LabVIEW 6.1 stuff is neat and lowish overhead compared to the fatware around today.

What is the memory available, use the task manager to dig a bit deeper. If the hard disk is fragmented then it could be thrashing as well when the virtual memory is being swapped.

There's not really enough information (OS, Memory .....) for a profesional analysis but I think it's safe to say the problem probably isn't with LabVIEW Smiley Tongue

0 Kudos
Message 2 of 8
(4,079 Views)
It is normal that a loop without any wait statement will consume all available CPU. It will spin as fast as possible. Why shouldn't it? 😮
 
A while loop itself does not consume huge amouts of memory, so your other application certainly has a different issue. Can you post the code? Are you building arrays to infinite size? What else is in that other loop?
0 Kudos
Message 3 of 8
(4,076 Views)
I'll have to try a simple experiment when I get home. I'll write a console app 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 waits 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 something 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
0 Kudos
Message 4 of 8
(4,071 Views)

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 programs 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 (from 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 long as no other tasks are requesting the CPU, which is probably why you're seeing a high CPU usage there.


___________________
Try to take over the world!
0 Kudos
Message 5 of 8
(4,043 Views)

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

0 Kudos
Message 6 of 8
(4,031 Views)


@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 the 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 put a 1ms delay in my usage stays close to zero. When I put in a 0ms delay, my 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, debugging enabled):
  1. No wait: The loop runs as fast as the CPU allows.Only every 55ms, it checks if something else needs attention, then continues. The loop spins about 100 million times/second. Actual rate depends on CPU speed.
  2. 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.
  3. 1ms wait: Same as case (2), but the loop waits ~1ms before continuing. Since 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, irrespective of CPU speed.

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

0 Kudos
Message 7 of 8
(4,030 Views)

On my main machine at work running LV with just a while loop and no delays, and my pc at home running the C while loop, 50% of the resources were used. On the machine at work running the "real" LV program, the one that actually does something, 100% of 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 what was causing the noise on my desktop pc when the while is running. I assumed it was disk access simply because there is not much else in the pc that causes noise, but it could be something else.

 

Chuck Gantz

0 Kudos
Message 8 of 8
(4,024 Views)