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.
-
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)
- 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.