473,480 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

for loop how to enhance performance

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

Nov 14 '05 #1
8 1752
Nirvana wrote:
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...

Nov 14 '05 #2

"Nirvana" <pa***********@hotmail.com> wrote in message
news:cp**********@newsg2.svr.pol.co.uk...
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.
Nov 14 '05 #3
Nirvana wrote:
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.

--
Best regards,
Andrey Tarasevich
Nov 14 '05 #4
On Mon, 06 Dec 2004 23:11:25 +0000, Nirvana
<pa***********@hotmail.com> wrote:
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.
Nov 14 '05 #5
"Tim Prince" <tp*****@nospamcomputer.org> writes:
"Nirvana" <pa***********@hotmail.com> wrote in message
news:cp**********@newsg2.svr.pol.co.uk...
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
In article <cp**********@newsg2.svr.pol.co.uk>, pa***********@hotmail.com
says...
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.

Nov 14 '05 #7
Nirvana wrote:

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.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #8
On Mon, 06 Dec 2004 23:11:25 +0000, Nirvana wrote:
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

Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
12010
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
39
2576
by: vineoff | last post by:
If I'm having nested loops like: for (...) for (..) for (...) { /* exit here */ } and I need to exit from there ^ . Is it better to use exceptions or goto or some other method?
7
2987
by: ssantamariagarcia | last post by:
I have found a problem while using a while statement and a linked list. I had never met this matter before....and I am wondering that if you have , please tell me what it is wrong. I am...
63
3153
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
15
2650
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
33
3010
by: dmoran21 | last post by:
Hi all, I am a mathematician and I'm trying to write a program to try out a formula that I've derived. However, it seems that I've got an infinite loop and I don't quite understand why. I was...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.