OMP: Error #34: System unable to allocate necessary resources for OMP thread:

在使用TensorFlow训练模型时,突然报错出现OMP线程过多的问题,网上查找了一下资料可以减少线程数,下面是报错的具体内容:
INFO:tensorflow:global step 80: loss = 2.3479 (3.266 sec/step)
INFO:tensorflow:global step 84: loss = 2.2638 (1.569 sec/step)
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.
Aborted (core dumped)
网上有人说通过设置环境变量参数改变线程数:
【OMP: Error #34: System unable to allocate necessary resources for OMP thread:】os.environ["OMP_NUM_THREADS"] = "12"
os.environ["KMP_BLOCKTIME"] = "1"
os.environ["KMP_AFFINITY"] = "granularity=fine,compact,1,0"
os.environ["KMP_SETTINGS"] = "0"
但是这种办法并不能解决这个问题
解决办法:

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


    推荐阅读