开发者

How to utilize my computation resources

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开发者_StackOverflow社区. 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


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.


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.


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜