for loop how to enhance performance

N

Nirvana

Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

Cheers
 
J

jacob navia

Nirvana said:
Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

Cheers

Use the CPU less.

The base of optimizations is to reduce the number of operations
the machine performs.

How to do that is difficult, specially since you do not post any
concrete code that can be improved...
 
T

Tim Prince

Nirvana said:
Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?
If your loop is small enough, depending on which platform you have in mind,
you may need to unroll the short loop entirely.
 
A

Andrey Tarasevich

Nirvana said:
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?
...

I hope you understand that if you make it to "occupy less cpu", the
entire manipulation will take longer. If that's what you want, you'll
have to consult Win32 documentation and/or Win32-specific run-time
library documentation in order to find out how to achieve that. There's
no C-standard way to do it.
 
B

Bart

Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

Cheers

99% cpu is as expected if nothing much else is running.

If you make your loop twice as efficient then you might use 99% cpu
for 5 seconds instead of 10 seconds. Post some sample code if you want
suggestions.

Unless of course you want your program to yield to other appls then
that's something else.

Bart.
 
K

Keith Thompson

Tim Prince said:
Nirvana said:
Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?
If your loop is small enough, depending on which platform you have in mind,
you may need to unroll the short loop entirely.

That might make the program finish more quickly, but it's not likely
to make it consume less than 99% of the CPU while it's running.

If you run a single CPU-intensive program, the operating system is
likely to allow that program to use most of the available CPU time.
Is that a problem? Was there something else you wanted to use the CPU
for while the program is running?

Your program is going to take a certain number of CPU cycles to run.
If you can convince your operating system to give only 50% of the CPU
to your program, it will take twice as long to finish. How to do that
is not a C question, and we can't help you with it here.

Reducing the number of cycles is a matter of optimization, something
we can't help you with without more details. Picking a better
algorithm and/or invoking the compiler with optimization options are
the most obvious things to try. Manual micro-optimization of your
source code, like unrolling your inner loop, is unlikely to be a good
use of your time; your compiler may do a better job of this than you
can, and your attempts may interfer with that.
 
R

Randy Howard

Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

Buy a faster computer, or at least post some code that shows the problem
so somebody might be able to figure it out instead of mindreading.
 
C

CBFalconer

Nirvana said:
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

Change that 20000000 value to 200.
 
L

Lawrence Kirby

Hello All,
I'm using for loop to manipulate a 2D int array of size [20000000][5].
The program is occupying 99% of CPU on my Win XP OS.

How to make this program to occupy less cpu ?

As others have said while a program is running it will use 100% of the CPU
(subject to multiprocessor, multicore, hyperthreading etc.)

If your real question is how to make the code take less CPU time then you
need to find a better algorithm. Since you don't say what your code is
supposed to do to this array or the algorithm you are currently using
there isn't much more we can say. However note that comp.lang.c isn't an
algorithms newsgroup (although some of us, myself not least, have been
known to sneak the odd algorithm discussion in). A good newsgroup for
discussing algorithms is comp.programming.

Lawrence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top