Hamza
Hamza

Reputation: 560

How to limit the number of cores of CPU used?

I am trying to use only single core of CPU. My system has 8 Cores. When I htop on terminal it should use only single core else all should remain silent. I am using below code but it is still using my all cores, what am I doing wrong ?

Code:

import tensorflow as tf

session_conf =  tf.ConfigProto(intra_op_parallelism_threads=1, 
                               inter_op_parallelism_threads=1,
                               device_count={'CPU': 1})

sess = tf.Session(config=session_conf)

It is utilizing all cores but with low percentage like 23 or 20 etc!

Upvotes: 1

Views: 967

Answers (1)

Bob
Bob

Reputation: 14654

Since you mention htop I assume you are in a linux system.

You can try to start your script using taskset, if your process start other processes you may want to set CPU affinity for each of them, by taskset -p <mask> <pid>.

Upvotes: 1

Related Questions