RussS
RussS

Reputation: 16576

POSIX Threads on a Multiprocessor System

I have written software which takes advantage of POSIX threads so that I can utilize shared memory within the process. My question is if I have a machine running Ubuntu with 4 processors and each processor has 16 cores. Is it more efficient to run 4 processes each with 16 threads or 1 process with 64 threads? Each processor has a dedicated 32gb of ram.

My main worry is that there will be a lot of memcopy happening behind the seen with 1 process.

In summary:
On a 4(16core) Proc Machine
1 process 64 threads?
4 Processes 16 Threads each?
If the process requires more than 32 gb of RAM(The amount dedicated to one Proc) does the answer differ?

Thanks for your help

Upvotes: 0

Views: 276

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136515

Depends on what your application does.

A thread in a single-threaded process runs faster then a thread in a multi-threaded process since the latter requires synchronization between threads in library functions like malloc(), fprintf(), etc.. Also, more threads in a multi-threaded process are likely to cause more lock contention slowing down each other. If threads don't need to communicate and don't share data they don't need to be in the same process.

In your case, you may get better parallelism with 4 processes with 16 threads rather then 1 process with 64 threads.

Upvotes: 1

Related Questions