# How to set intra\_\* and inter\_\* parallelism\_threads parameters in TensorFlow

**URL:** <https://ask.cyberinfrastructure.org/t/how-to-set-intra-and-inter-parallelism-threads-parameters-in-tensorflow/1514>\
**Category:** Q&A\
**Tags:** tensorflow\
**Created:** [September 25, 2020, 4:04pm UTC](https://ask.cyberinfrastructure.org/t/how-to-set-intra-and-inter-parallelism-threads-parameters-in-tensorflow/1514 "2020-09-25T16:04:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktrn](https://ask.cyberinfrastructure.org/user_avatar/ask.cyberinfrastructure.org/ktrn/32/554_2.png) [@ktrn](https://ask.cyberinfrastructure.org/u/ktrn)\
**Post date:** [September 25, 2020, 4:04pm UTC](https://ask.cyberinfrastructure.org/t/how-to-set-intra-and-inter-parallelism-threads-parameters-in-tensorflow/1514/1 "2020-09-25T16:04:28Z")

</div>

By default, TensorFlow uses all CPU cores. To make sure the number of cores it uses, does not exceed the number of cores requested by a job on a cluster, one needs to set 2 parameters:  
**inter\_op\_parallelism\_threads** and **intra\_op\_parallelism\_threads**.

_What is the best way to determine the values for these parameters?_

I set them as follows:  
`inter_op_parallelism_threads = 1`  
`intra_op_parallelism_threads = n_cores -1`  
and it works,  
but I wonder if there are some recommendations on how to choose these values to make my code run in most efficient way.  
Also, _does the way I should set these parameters depend on the number of GPUs I use (none, one, more)_?

---

<div class="post-metadata">

**Author:** ![wirawan0](https://ask.cyberinfrastructure.org/user_avatar/ask.cyberinfrastructure.org/wirawan0/32/362_2.png) [@wirawan0](https://ask.cyberinfrastructure.org/u/wirawan0)\
**Post date:** [September 30, 2020, 2:48am UTC](https://ask.cyberinfrastructure.org/t/how-to-set-intra-and-inter-parallelism-threads-parameters-in-tensorflow/1514/2 "2020-09-30T02:48:00Z")

</div>

I want to add a follow-up, related question. In my limited experience with this, I was not sure whether the cores (in CPU-based TensorFlow) were used efficiently. How can we know if the choices we have result in optimal CPU utilization (i.e. maximizing work so we can complete in the shortest time).
