views:

73

answers:

4

Hi all,

I wrote a program to solve a complicated problem. This program is just a c# console application and doesn't do console.write until the computation part is finished, so output won't affect the performance. The program is like this:

static void Main(string[] args)
        {

            Thread WorkerThread = new Thread(new ThreadStart(Run), StackSize);
            WorkerThread.Priority = ThreadPriority.Highest;
            WorkerThread.Start();
            Console.WriteLine("Worker thread is runing...");
            WorkerThread.Join();
        }

Now it takes 3 minute to run, when I open my task manager, I see it only take 12% of the cpu time. I actually have a i7 intel cpu with 6G three channel DDR3 memory. I am wondering how I can improve the utilization of my hardware.

Thanks a lot

A: 

1 thread can only occupy 1 core, so you need to separate the task into several threads to utilize your CPU. Are your absolutely sure you are not doing IO operations in your algorithm?

HeavyWave
yes, I am sure. the only thing I used is memory. Thanks.
Well, maybe your CPU spends most of the time waiting for memory. In any case with 1 thread you won't be able to use more than 25% of your CPU.
HeavyWave
A: 

Find out what it's spending it's time doing, percentage-wise. This is the method I use, regardless of platform. I've had programs where I was sure I wasn't doing any I/O and guess what? I was, for the most obscure reasons.

Mike Dunlavey
+1  A: 

Your i7 supports hyper threading, so a quad-core i7 can handle eight threads simultaneously.

Your program seems to use one thread, so the Windows task manager will show you a CPU usage of 12 - 13 % simply because you utilise one of the eight available "virtual" CPUs.

As HeavyWave said, you need to find a way to split up your computation into more threads that you can run in parallel to get a higher cpu usage.

Novox
+1  A: 

An Intel i7 should report as 8 cores (4 physical cores, each reporting as 2-cores, due to hyper-threading).

By starting one single thread, you should get 12.5% of the CPU, overall. Which is almost perfectly inline with what you describe.

One thread cannot and will not run across multiple cores consuming all the resources. If you want to use more resources, you need to start multiple threads. Ideally, you'll need a minimum of 4 threads, and more likely 6 to 8 threads to approach 100% utilization.

To do this, you need to find a way to break up your "complicated problem" into parallelizable instruction paths.

abelenky