Take the 2-minute tour ×

I am running a simple C program which performs a lot calculations(CFD) hence takes a lot of time to run. However i still have a lot of unused CPU and RAM. So how will i allocate some of my processing power to one program.??

share|improve this question
You are probably running on a multiple core cpu but are not using multithreading? –  Pankrates Feb 9 '13 at 10:18
Are you sure that your program fully loads CPU? –  Eddy_Em Feb 9 '13 at 10:18
Yes.. It took around 1 1/2 hours to complete its execution but cpu usage didnt cross 30% !! Also i have not used threads in my code.. –  leet Feb 9 '13 at 10:28
How many cores do you have? –  user570500 Feb 9 '13 at 10:44
You should probably rephrase the title. The resources are available to your program and do not need to be allocated, but your program is not using them completely. –  William Pursell Feb 9 '13 at 13:29

4 Answers 4

up vote 2 down vote accepted

I'm guessing that CFD means Computational Fluid Dynamics (but CFD has also a lot of other meanings, so I might guess wrong).

You definitely should first profile your code. At the very least, compile it with gcc -Wall -pg -O and learn how to use gprof. You might also use strace to find out the system calls done by your code.

I'm not an expert of CFD (even if in the previous century I did work with CFD experts). But such code uses a lot of finite elements analysis and other vector computation.

If you are writing the code, you might perhaps consider using OpenMP (so by carefully adding OpenMP pragmas in your source code, you might speed it up), or even consider using GPGPUs by coding OpenCL kernels that run on the GPU.

You could also learn more about pthreads programming and change your code to use threads.

If you are using important numerical libraries like e.g. BLAS they have a lot of tuning, and even specialized variants (e.g. multi-core, OpenMP-ed, or even in OpenCL).

In all cases, parallelizing your code is a lot of work. You'll spend weeks or months on improving it, if it is possible.

share|improve this answer

Linux doesn't keep programs waiting and CPU free when they need to do calculations. Either you have a multicore CPU and one single thread running (as suggested by @Pankrates) or you are blocking on some I/O.

share|improve this answer
The program perform certain huge mathematical computations.. I can only see 30% of my cpu and 21% of 6GB RAM and 2.13GHz i3 CPU –  leet Feb 9 '13 at 10:32
i3 cpus have this: en.wikipedia.org/wiki/Multi-core_processor they are somewhat like several processors built together. But a program runs sequentially so only one processor can run it, the other processors are left unused. You should check if your algorithm allows some parallel execution. This is a complex argument so do a lot of reading before starting. –  LtWorf Feb 9 '13 at 10:44

You could nice the process with a negative increment, but you need to be superuser for that. See

man nice

This would increase the scheduling priority of the process. If it is competing with other processes for CPU time, it would get more CPU time and therefore "run faster".

As for increasing the amount of RAM used by the program: you'd need to rewrite or reconfigure the program to use more RAM. It is difficult to say more given the information available in the question.

share|improve this answer
I dont think that processes are competing coz i have a lot of unused RAM and CPU left !! –  leet Feb 9 '13 at 10:36
It is possible that it is blocked on IO. If that is not the case, you'd need to rewrite the program to use multithreading to make it use more CPU. –  user570500 Feb 9 '13 at 10:43
Also: maybe it is not CPU bound, but memory bound. Look for places in your code where data from memory locations that are far apart is accessed. –  user570500 Feb 9 '13 at 10:47

To use multiple CPU's at once, you either need to run multiple copies of your program, or run multiple threads within the program. Neither is terribly hard to get started on.

However, it's much easier to do a parallel version of "I've got 10000 large numbers, I want to find out for each of them if they are primes or not" than it is to do "lots of A = A + B" type calculations in parallel - because you need the new A before you can make the next step. CFD calculations tend to do the latter [as far as I understand it], but with large arrays. You may be able to split large vector calculations into a set of smaller vector caclulations [say we have a matrix of 1000 x 1000, you could split that into 4 sets of 250 x 1000 matrixes, or 4 sets of 500 x 500 matrixes, and perform each of those in it's own thread].

If it's your own code, then you hopefully know what it does and how it works. If it's someone elses code, then you need to talk to whoever owns the code.

There is no magical way to "automatically make use of more CPU's". 30% CPU usage on a quad-core processor probably means that your system is basically using one core, and 5% or so is overhead for other things going on in the system - or maybe there is a second thread somewhere in your application that uses a little bit of CPU doing whatever it does. Or the application is multithreaded, but doesn't use the multiple cores to full extent because there is contention between the threads over some shared resource... It's impossible for us to say which of these three [or several other] alternatives.

Asking for more RAM isn't going to help unless you have something useful to put into that memory. If there is free memory, your application get as much memory as it needs.

share|improve this answer

Your Answer


