0

I have small c program that use lot of cpu , this program compiled to exe , and I run it as a process from my c# gui.

When I want to run it parallel on all over my cpu cores ,I have 2 options.

I have 4 cpu cores.

  1. Run this c exe from my c# as 4 process so my os seperate those process 1 for each core .

  2. Edit my c code so it run 4 thread so os will seperate 1 thread for each core, and from c# I will run it as 1 process.

Which way will be faster?

Edit: those processes/ thread will run like 3-5 houres ,and dont need to communicate between anotger thread/ process.

All of this running on windows

  • 3
    It will depend on a lot of factors, such as how long the process(es) run for, what operations they perform, whether (and how much) they need to communicate with each other, and so on. The best way to find out is to try it both ways and see if it makes a difference, and if so, how much. – Jeremy Friesner Oct 29 '18 at 22:37
  • you need to provide more information. it is quite possible to run slower on parallel threads than in a single thread, depending on the tasks they do. – Serge Oct 29 '18 at 23:30

2 Answers2

0

Running 4 threads in C will be faster than running 4 processes in C#.

There is a higher penalty for switching between processes than for switching between threads and communication between processes is slower than between threads.

0

Allocate a process require more time that allocate a thread, because threads share the resources (code, data...)

If your cpu continuously change processes (this usually happens) is not better solution using the processes, using of thread is more efficent and specially with a single cpu systems...

https://stackoverflow.com/a/200543/3476815

gfdevelop
  • 187
  • 2
  • 7