首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >以普通用户身份运行代码时,OpenMP:"libgomp:线程创建失败:资源暂时不可用“

以普通用户身份运行代码时,OpenMP:"libgomp:线程创建失败:资源暂时不可用“
EN

Stack Overflow用户
提问于 2018-11-17 20:20:18
回答 2查看 9.9K关注 0票数 2

当我运行以下示例代码时:

代码语言:javascript
运行
复制
#include "stdio.h"
#include <omp.h>

int main(int argc, char *argv[])
{
  #pragma omp parallel
  {
   int NCPU,tid,NPR,NTHR;
    /* get the total number of CPUs/cores available for OpenMP */
   NCPU = omp_get_num_procs();
   /* get the current thread ID in the parallel region */
   tid = omp_get_thread_num();
   /* get the total number of threads available in this parallel region */
   NPR = omp_get_num_threads();
   /* get the total number of threads requested */
   NTHR = omp_get_max_threads();
   /* only execute this on the master thread! */

   if (tid == 0) {
     printf("%i : NCPU\t= %i\n",tid,NCPU);
     printf("%i : NTHR\t= %i\n",tid,NTHR);
     printf("%i : NPR\t= %i\n",tid,NPR);
   }
   printf("%i : hello multicore user! I am thread %i out of %i\n",tid,tid,NPR);
  }
  return(0);
 }

使用命令:gcc -fopenmp example.c -o example.exe然后./example,我得到了错误:libgomp: Thread creation failed: Resource temporarily unavailable。但是,当我在sudo下运行相同的代码和命令时,我得到了预期的输出:

代码语言:javascript
运行
复制
0 : NCPU    = 4
0 : NTHR    = 4
0 : NPR = 4
2 : hello multicore user! I am thread 2 out of 4
1 : hello multicore user! I am thread 1 out of 4
0 : hello multicore user! I am thread 0 out of 4
3 : hello multicore user! I am thread 3 out of 4

我在4核的x86_64架构上运行Ubuntu18.04。

代码语言:javascript
运行
复制
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  2
Core(s) per socket:  2
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               78
Model name:          Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz

以root用户的身份使用Openmp运行c代码真的很不舒服。我的问题是,有人能提供为什么会发生这种情况的信息吗?谢谢

EN

Stack Overflow用户

发布于 2021-09-10 13:50:42

修复错误:

代码语言:javascript
运行
复制
"libgomp: Thread creation failed: Resource temporarily unavailable"

特别是在只有1-cpu的系统中,只需要减少线程:

代码语言:javascript
运行
复制
export OMP_NUM_THREADS=1

继续..。

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53351194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档