Reputation: 1177
I've read that when you run a long running operation in separate threads (in parallel) there will be noticeable improvement in performance when your PC has multiple processor cores. In C# there is a function Parallel.ForEach
which, how I understand, splits the long running operation in separate threads which are ran on each processor core. Although, if there is only one core, this function will run as a simple Foreach
loop (synchronous). Also, if you are creating more threads than there is processor cores, it may even have a negative impact.
I was thinking of creating a separate console application, pass args
to it and run it's .exe on multiple processes like start -WindowStyle Hidden SeparateProcess.exe
.
Edit:
I already created a console app like this
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(200);
Console.WriteLine("" + i);
}
Console.WriteLine();
Console.WriteLine(Guid.NewGuid() + ": Process finalized.");
}
}
Then, using powershell executed it many times:
For ($i=0; $i -lt 10; $i++){
start -WindowStyle Normal SeparateProcess.exe
}
Will this improve program performance when ran on single core?
Note: The long running task is Emgu CV image computing algorithm.
Upvotes: 0
Views: 517
Reputation: 89242
You should check yourself by trying it, but ...
Is there a way to improve long running task performance even when there is only one core?
Yes, but obviously not by running it in parallel. You would use a performance analyzer on the code to find out which parts were taking the most time and try to rewrite it in a more optimized way.
EDIT based on comments:
If you are trying to do image-processing with CV and the thing you are doing is CPU-bound (maxes out the processor while running), then parallelizing it isn't going to help on a single core (they will compete with each other for CPU).
If the thing you are doing has to wait for I/O to complete, then parallelizing it will allow some of the work to go forward while other processes wait on the I/O.
It depends on what you are doing -- you should probably close this question and ask a much more specific one with details on exactly what you are trying to do and how CPU-intensive that task is.
(BTW, if you can, one way to make image processing go faster is to resize the image beforehand -- many things you might try to do with an image work fine on a smaller version -- for example: face detection).
Upvotes: 1