Search code examples
c#performancemultithreadingutilization

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. 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


Solution

  • 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?