Skip to content

Instantly share code, notes, and snippets.

@qin-yu
Last active May 7, 2021 18:05
Show Gist options
  • Save qin-yu/b3da088669db84f87a2541578cf7fa60 to your computer and use it in GitHub Desktop.
Save qin-yu/b3da088669db84f87a2541578cf7fa60 to your computer and use it in GitHub Desktop.
OMP: Error #34: System unable to allocate necessary resources for OMP thread; OMP: System error #11: Resource temporarily unavailable; OMP: Hint Try decreasing the value of OMP_NUM_THREADS.

OMP: Error #34 Solution

by Qin Yu, May 2021

If you get the following error during training with TensorFlow, then this is relevant to you (though this is an OpenMP/OMP error):

OMP: Error #34: System unable to allocate necessary resources for OMP thread:
OMP: System error #11: Resource temporarily unavailable
OMP: Hint Try decreasing the value of OMP_NUM_THREADS.

Solution 1

  • Put the following lines at the beginning of your code to configure threading for TensorFlow v2:

    tf.config.threading.set_inter_op_parallelism_threads(4)
    tf.config.threading.set_intra_op_parallelism_threads(16)
  • If you are using TensorFlow v1, use this instead (also explained by this post):

    config = tf.ConfigProto()
    config.intra_op_parallelism_threads = 12
    config.inter_op_parallelism_threads = 2
    tf.session(config=config)

Solution 2

  • Run your code with the environment variable OMP_NUM_THREADS=1, which turns off the threading of OpenMP and will probably make you code slower/faster depending on the exact situation (also explained by this post). For example:
    $ CUDA_VISIBLE_DEVICES=6 OMP_NUM_THREADS=1 nohup python your_script.py &> log.txt &

The problem should be solved now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment