0
我使用Ubuntu并编写了几行代码。但它只创建一个线程。当我在我的终端上运行nproc
命令时,输出为2。我的代码如下OpenMP只创建一个线程
int nthreads, tid;
#pragma omp parallel private(tid)
{
tid = omp_get_thread_num();
printf("Thread = %d\n", tid);
/* for only main thread */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
输出:
Thread = 0
Number of threads = 1
我该怎么办并行?
ok。我明白了。再次敲击。 – andressophia 2014-09-26 01:43:22
不客气。很高兴你得到它我修改我的答案更多的细节。另外我还提到了OMP_NUM_THREADS环境变量。 – 2014-09-26 01:52:17
我刚试过这些。感谢您的回答。 – andressophia 2014-09-26 02:05:25